<template>
  <div>
    <div style="padding-bottom: 70px;" class="app-container calendar-list-container">
      <div class="yt-data-template">
        <div class="yt-data-list">
          <div class="yt-list-title">
            <span>{{$t('scheduleManager.worksDetails.baseTitle')}}</span><!--工务基本讯息-->
          </div>
          <div>
            <el-form :inline="true" style="padding: 0 20px 10px">
              <el-row>
                <el-col :span="4" style="display: inline-block">
                  <div class="w20">
                    <div class="labelName" style="color:red">*{{$t('scheduleManager.worksDetails.systemType')}}</div><!--系统别-->
                    <yt-select v-model="projectProgress.systemType" @selectedChange="selectedChange" :disabled="id&&id!='addWorks'?true:false" :clearable ="false" :listData="this.$store.getters.allDic.systemType"></yt-select>
                  </div>
                </el-col>
                <yt-template v-if="basicList.length > 0" :systemType="projectProgress.systemType" :id="id" :data="projectProgress" :dataTemplate="basicList" :tableName="tableName"></yt-template>
              </el-row>
            </el-form>
          </div>
        </div>

        <div class="yt-data-list">
          <div class="yt-list-title">
            <span>{{$t('scheduleManager.worksDetails.contractContent')}}</span><!--1、合约内容-->
          </div>
          <div v-if="contract.length > 0">
            <el-form :inline="true" style="padding: 0 20px">
              <el-row style="padding-bottom: 10px">
                <yt-template v-if="contract.length > 0" :systemType="projectProgress.systemType" :id="id" :data="projectProgress" :dataTemplate="contract" :tableName="tableName"></yt-template>
              </el-row>
            </el-form>
          </div>
          <div style="padding: 10px; text-align: center;" v-else>{{$t('scheduleManager.worksDetails.noData')}}</div><!--暫無數據-->
        </div>

        <div class="yt-data-list">
          <div class="yt-list-title">
            <span>{{$t('scheduleManager.worksDetails.projectImplement')}}</span><!--2、工程执行-->
          </div>
          <div v-if="engineering.length > 0">
            <el-form :inline="true" style="padding: 0 20px 0">
              <el-row style="padding-bottom: 10px">
                <yt-template v-if="engineering.length > 0"
                             :systemType="projectProgress.systemType"
                             :id="id" :data="projectProgress"
                             :dataTemplate="engineering"
                             :tableName="tableName">
                </yt-template>
              </el-row>
            </el-form>
          </div>
          <div style="padding: 10px; text-align: center;" v-else>{{$t('scheduleManager.worksDetails.noData')}}</div><!--暫無數據-->
        </div>
      </div>

      <!-- 3、请款作业 -->
      <div class="yt-data-list">
        <div class="yt-list-title">
          <span>{{$t('scheduleManager.worksDetails.receiveWorks')}}</span><!--3、请款作业-->
        </div>
        <div class="yt-list-content">
          <div class="list-operation">
            <!--新增-->
            <div class="yt-btn yt-btn-ys" @click="newly">{{ $t("button.new") }}</div>
            <!--删除-->
            <div class="yt-btn yt-ml8" @click="handleDelete('del')">{{ $t("button.delete") }}</div>
          </div>
          <el-table :data="list.slice((requestCurrentPage-1)*requestPageSize,requestCurrentPage*requestPageSize)" :empty-text="$t('placeholder.emptyText')" max-height="500" class="yt-table yt-temporary" border @selection-change="handleSelectionChange" @sort-change="sortDate">
            <el-table-column align="center" label="Sum">
              <el-table-column align="center" type="selection" width="60" />
              <el-table-column align="center" type="index" :label="$t('projectProcess.index.serialNumber')" width="60"/>
            </el-table-column>
            <el-table-column align="center" :label="projectRequestFundsVo.paymentType">
              <!--客戶付款條件-->
              <el-table-column align="center" :label="$t('scheduleManager.worksDetails.constomerPayCondition')" width="300" sortable="custom" prop="paymentType"><!--客戶付款條件-->
                <template slot-scope="scope">
                  <div class="display_center">
                    <el-select class="filter-item" v-model="scope.row.paymentType"  :placeholder="$t('scheduleManager.worksDetails.pleaseEnter')" style="flex:1"><!--请输入-->
                      <el-option v-for="item in paymentTypeList" :key="item.value" :label="item.label" :value="item.value"></el-option>
                    </el-select>
                    <el-input :maxlength="100" v-if="scope.row.paymentType === 'other'" v-model="scope.row.paymentTypeText" :placeholder="$t('scheduleManager.worksDetails.pleaseEnterOtherAgain')" clearable class="filter-item" style="flex:2"></el-input><!--请输入其他条件-->
                  </div>
                </template>
              </el-table-column>
            </el-table-column>
            <!--請款金額-->
            <el-table-column align="center" :label="projectRequestFundsVo.requestFundsMoney">
              <el-table-column align="center" :label="$t('scheduleManager.worksDetails.pleaseMoney')" width="160" sortable="custom" prop="requestFundsMoney"><!--請款金額-->
                <template slot-scope="scope">
                  <div v-check-submit tabindex="0">
                    <el-input :maxlength="100" style="display: none" type="number" :placeholder="$t('placeholder.content')" size="small" @input="requestFundsMoney(scope.row)" v-model="scope.row.requestFundsMoney"></el-input><!--请输入内容-->
                    <div class="box" v-format="'#,##0'" :placeholder="$t('placeholder.content')">{{ scope.row.requestFundsMoney }}</div>
                  </div>
                </template>
              </el-table-column>
            </el-table-column>
            <!--未開發票預計收款日(資金預估)-->
            <el-table-column align="center" :label="projectRequestFundsVo.capitalProjectionDate">
              <el-table-column align="center" :label="$t('scheduleManager.worksDetails.unWriteInvoice')" width="220" sortable="custom" prop="capitalProjectionDate"><!--未開發票預計收款日(資金預估)-->
                <template slot-scope="scope">
                  <el-date-picker v-model="scope.row.capitalProjectionDate" :placeholder="$t('scheduleManager.worksDetails.pleaseSelect')" class="dateTime yt-table-picker" type="date" :value-format="format" :format="format"/><!--请选择-->
                </template>
              </el-table-column>
            </el-table-column>
            <!--通知開發票日-->
            <el-table-column align="center" :label="projectRequestFundsVo.noticeInvoiceDate">
              <el-table-column align="center" :label="$t('scheduleManager.worksDetails.tellInvoiceDate')" width="220" sortable="custom" prop="noticeInvoiceDate"><!--通知開發票日-->
                <template slot-scope="scope">
                  <el-date-picker v-model="scope.row.noticeInvoiceDate" :placeholder="$t('scheduleManager.worksDetails.pleaseSelect')" class="dateTime yt-table-picker" type="date" :value-format="format" :format="format"/><!--请选择-->
                </template>
              </el-table-column>
            </el-table-column>
            <!--ERP應收單號-->
            <el-table-column align="center" :label="projectRequestFundsVo.erpReceivablesNo">
              <el-table-column align="center" :label="$t('scheduleManager.worksDetails.ERPReceiveNo')" width="160" sortable="custom" prop="erpReceivablesNo"><!--ERP 應收單號-->
                <template slot-scope="scope">
                  <el-input :maxlength="100" :placeholder="$t('scheduleManager.worksDetails.pleaseSelect')" v-model="scope.row.erpReceivablesNo" @blur="getQueryByExample(scope.row)"></el-input><!--请输入-->
                </template>
              </el-table-column>
            </el-table-column>
            <!--分次收款-->
            <el-table-column align="center" :label="projectRequestFundsVo.requestIs">
              <el-table-column align="center" :label="$t('scheduleManager.worksDetails.requestIs')" width="100" sortable="custom" prop="requestIs"><!--是否请款-->
                <template slot-scope="scope">
                  <el-checkbox :disabled="!scope.row.erpReceivablesNo" style="margin-right: 10px" true-label="1" false-label="0" v-model="scope.row.requestIs"></el-checkbox>
                </template>
              </el-table-column>
            </el-table-column>
            <!--開發票日期-->
            <el-table-column align="center" :label="projectRequestFundsVo.invoiceDate">
              <el-table-column align="center" :label="$t('scheduleManager.worksDetails.writeInvoiceDate')" width="220" sortable="custom" prop="invoiceDate"><!--開發票日-->
                <template slot-scope="scope">
                  <el-date-picker @change="requestFundsMoney(scope.row)" v-model="scope.row.invoiceDate" :placeholder="$t('scheduleManager.worksDetails.pleaseSelect')" class="dateTime yt-table-picker" type="date" :value-format="format" :format="format"/><!--请选择-->
                </template>
              </el-table-column>
            </el-table-column>
            <!--發票號碼-->
            <el-table-column align="center" :label="projectRequestFundsVo.invoiceNo">
              <el-table-column align="center" :label="$t('scheduleManager.worksDetails.invoiceNo')" width="160" sortable="custom" prop="invoiceNo"><!--發票號碼-->
                <template slot-scope="scope">
                  <el-input :maxlength="100" @blur="getQueryByExample(scope.row)" :placeholder="$t('scheduleManager.worksDetails.pleaseSelect')" v-model="scope.row.invoiceNo"></el-input><!--请输入-->
                </template>
              </el-table-column>
            </el-table-column>
            <!--發票金額-->
            <el-table-column align="center" :label="projectRequestFundsVo.invoiceMoney">
              <el-table-column align="center" :label="$t('scheduleManager.worksDetails.invoiceMoney')" width="160" sortable="custom" prop="invoiceMoney"><!--發票金額-->
                <template slot-scope="scope">
                  <div v-check-submit tabindex="0">
                    <el-input :maxlength="100" style="display: none" type="number" :placeholder="$t('placeholder.content')" size="small" v-model="scope.row.invoiceMoney"></el-input><!--请输入-->
                    <div class="box" v-format="'#,##0'" :placeholder="$t('placeholder.content')">{{ scope.row.invoiceMoney }}</div>
                  </div>
                </template>
              </el-table-column>
            </el-table-column>
            <el-table-column align="center" :label="projectRequestFundsVo.expectedReceivablesDate">
              <!--預計收款日-->
              <el-table-column align="center" :label="$t('scheduleManager.worksDetails.expectedReceivablesDate')" width="220" sortable="custom" prop="expectedReceivablesDate">
                <template slot-scope="scope">
                  <yt-template-time v-model="scope.row.expectedReceivablesDate"></yt-template-time>
                </template>
              </el-table-column>
            </el-table-column>
            <el-table-column align="center" :label="projectRequestFundsVo.realityReceivablesDate">
              <!--實際收款日-->
              <el-table-column align="center" :label="$t('scheduleManager.worksDetails.realityReceivablesDate')" width="220" sortable="custom" prop="realityReceivablesDate">
                <template slot-scope="scope">
                  <el-date-picker @change="requestFundsMoney(scope.row)" v-model="scope.row.realityReceivablesDate" :placeholder="$t('scheduleManager.worksDetails.pleaseSelect')" class="dateTime yt-table-picker" type="date" :value-format="format" :format="format"/><!--请选择-->
                </template>
              </el-table-column>
            </el-table-column>
            <el-table-column align="center" :label="projectRequestFundsVo.receivablesMoney">
              <!--收款金額-->
              <el-table-column align="center" :label="$t('scheduleManager.worksDetails.receivablesMoney')" width="160" sortable="custom" prop="receivablesMoney">
                <template slot-scope="scope">
                  <div v-check-submit tabindex="0">
                    <!--请输入-->
                    <el-input :maxlength="100" style="display: none" type="number" :placeholder="$t('placeholder.content')" size="small" v-model="scope.row.receivablesMoney"></el-input>
                    <div class="box" v-format="'#,##0'" :placeholder="$t('placeholder.content')">{{ scope.row.receivablesMoney }}</div>
                  </div>
                </template>
              </el-table-column>
            </el-table-column>
            <el-table-column align="center" :label="projectRequestFundsVo.receivableRemark">
              <!--收款備註-->
              <el-table-column align="center" :label="$t('scheduleManager.worksDetails.receivableRemark')" width="160" sortable="custom" prop="receivableRemark">
                <template slot-scope="scope">
                  <!--请输入-->
                  <el-input :maxlength="200" :placeholder="$t('scheduleManager.worksDetails.pleaseSelect')" v-model="scope.row.receivableRemark"></el-input>
                </template>
              </el-table-column>
            </el-table-column>
            <el-table-column align="center" :label="projectRequestFundsVo.deductionMoney">
              <!--扣款金額-->
              <el-table-column align="center" :label="$t('scheduleManager.worksDetails.deductionMoney')" width="160" sortable="custom" prop="deductionMoney">
                <template slot-scope="scope">
                  <div v-check-submit tabindex="0">
                    <!--请输入-->
                    <el-input :maxlength="100" style="display: none" type="number" :placeholder="$t('placeholder.content')" size="small" v-model="scope.row.deductionMoney"></el-input>
                    <div class="box" v-format="'#,##0'" :placeholder="$t('placeholder.content')">{{ scope.row.deductionMoney }}</div>
                  </div>
                </template>
              </el-table-column>
            </el-table-column>


          </el-table>
        </div>
        <div class="pagination-container" style="margin:0 20px 10px">
          <el-pagination @size-change="handleSizeRequestChange" @current-change="handleCurrentRequestChange" background :hide-on-single-page="false" :current-page.sync="requestCurrentPage" :page-sizes="[10, 20, 30, 50, 100, 200]" :page-size="requestPageSize" layout="total, sizes, prev, pager, next, jumper" :total="list.length"></el-pagination>
        </div>
      </div>

      <!-- 4、厂商管理 -->
      <div class="yt-data-list">
        <div class="yt-list-title">
          <span>{{$t('scheduleManager.worksDetails.vendorManagement')}}</span>
        </div>
        <div class="yt-list-content">

          <div class="list-operation">

            <el-row >
              <el-col :span="4" >
                <!--新增-->
                <div class="yt-btn yt-btn-ys" @click="vendorAdd">{{ $t("button.new") }}</div>
                <!--删除-->
                <div class="yt-btn yt-ml8" @click="vendorDelete('del')">{{ $t("button.delete") }}</div>
                <!--下载-->
                <div class="yt-btn yt-btn-ys yt-ml8" @click="downloadAppraise">{{$t('scheduleManager.worksDetails.download')}}</div>

              </el-col>
              <el-col :span="4">
                  <el-input v-model="likeVendor" :placeholder="$t('scheduleManager.progressList.eneterVendorPoNoPlaceholder')" clearable class="filter-item"></el-input>
              </el-col>
              <el-col :span="4"  style="margin-left: 12px" >
                <div class="yt-btn yt-btn-ys" @click="queryVendor">{{$t('scheduleManager.progressList.query')}}</div> <!--查询-->
              </el-col>

            </el-row>

          </div>
          <el-table :data="filterVendor?vendorList.filter(v=> v.v).slice((vendorCurrentPage-1)*vendorPageSize,vendorCurrentPage*vendorPageSize):vendorList.slice((vendorCurrentPage-1)*vendorPageSize,vendorCurrentPage*vendorPageSize)" :empty-text="$t('placeholder.emptyText')" max-height="500" class="yt-table yt-temporary" border @selection-change="vendorSelectionChange" @sort-change="sortDate2">
            <el-table-column align="center" label="Sum" fixed width="120">
              <el-table-column align="center" type="selection"width="60"/>
              <el-table-column align="center" type="index" :label="$t('projectProcess.index.serialNumber')" width="60"/>
            </el-table-column>
            <!--BU/BG-->
            <el-table-column align="center" label="" fixed width="100">
              <!--bu-->
              <el-table-column align="center" label="Account" width="100" sortable="custom" prop="bu">
                <template slot-scope="scope">
                  <el-select filterable clearable @change="((val)=>{setBu(val, scope.row)})" v-model="scope.row.bu" :placeholder="$t('placeholder.choose')">
                    <el-option v-for="(item, index) in buList" :key="index" :label="item.bu" :value="item.bu"></el-option>
                  </el-select>
                </template>
              </el-table-column>
            </el-table-column>
            <el-table-column align="center" label="" fixed width="100">
              <!--bg-->
              <el-table-column align="center" label="Category" width="100" sortable="custom" prop="bg">
                <template slot-scope="scope">
                  <el-select v-model="scope.row.bg" :placeholder="$t('placeholder.choose')" >
                    <el-option v-for="item in bgList" :key="item" :label="item" :value="item"></el-option>
                  </el-select>
                </template>
              </el-table-column>
            </el-table-column>



            <el-table-column align="center" :label="projectVendorVo.vendorName" fixed width="100">
              <!--厂商简称-->
              <el-table-column align="center" :label="$t('scheduleManager.worksDetails.vendorName')" width="100" sortable="custom" prop="vendorName">
                <template slot-scope="scope">
                  <!--请输入厂商简称/名称-->
                  <popover-select selectType="vendor" valueObjName="vendorShortName" v-model="scope.row.vendorName" @input="(val,item) => setVendor(item, scope.row)" :placeholder="$t('scheduleManager.worksDetails.vendorPlaceholder')"></popover-select>
                </template>
              </el-table-column>
            </el-table-column>
            <el-table-column align="center" :label="projectVendorVo.vendorOfferMoney">
              <!--廠商報價金額-->
              <el-table-column align="center" :label="$t('scheduleManager.worksDetails.vendorOfferMoney')" width="160" sortable="custom" prop="vendorOfferMoney">
                <template slot-scope="scope">
                  <div v-check-submit tabindex="0">
                    <!--请输入内容-->
                    <el-input :maxlength="100" style="display: none" type="number" :placeholder="$t('placeholder.content')" size="small" v-model="scope.row.vendorOfferMoney"></el-input>
                    <div class="box" v-format="'#,##0'" :placeholder="$t('placeholder.content')">{{ scope.row.vendorOfferMoney }}</div>
                  </div>
                </template>
              </el-table-column>
            </el-table-column>
            <el-table-column align="center" :label="projectVendorVo.vendorItem">
              <!--廠商工項-->
              <el-table-column align="center" :label="$t('scheduleManager.worksDetails.vendorItem')" width="160" sortable="custom" prop="vendorItem">
                <template slot-scope="scope">
                  <!--请输入内容-->
                  <el-input :maxlength="200" :placeholder="$t('scheduleManager.worksDetails.pleaseEnterContent')" v-model="scope.row.vendorItem"></el-input>
                </template>
              </el-table-column>
            </el-table-column>
            <el-table-column align="center" :label="projectVendorVo.vendorPoNo">
              <!--廠商PO單號-->
              <el-table-column align="center" :label="$t('scheduleManager.worksDetails.vendorPoNo')" width="160" sortable="custom" prop="vendorPoNo">
                <template slot-scope="scope">
                  <!--请输入内容-->
                  <el-input :maxlength="100" :placeholder="$t('scheduleManager.worksDetails.pleaseEnterContent')" v-model="scope.row.vendorPoNo"></el-input>
                </template>
              </el-table-column>
            </el-table-column>
            <el-table-column align="center" :label="projectVendorVo.vendorPoMoney">
              <!--廠商PO金額-->
              <el-table-column align="center" :label="$t('scheduleManager.worksDetails.vendorPoMoney')" width="220" sortable="custom" prop="vendorPoMoney">
                <template slot-scope="scope">
                  <div v-check-submit tabindex="0">
                    <!--请输入内容-->
                    <el-input :maxlength="100" style="display: none" type="number" :placeholder="$t('placeholder.content')" size="small" v-model="scope.row.vendorPoMoney"></el-input>
                    <div class="box" v-format="'#,##0'" :placeholder="$t('placeholder.content')">{{ scope.row.vendorPoMoney }}</div>
                  </div>
                </template>
              </el-table-column>
            </el-table-column>
            <el-table-column align="center" :label="projectVendorVo.vendorPayCondition">
              <!--廠商付款條件-->
              <el-table-column align="center" :label="$t('scheduleManager.worksDetails.vendorPayCondition')" width="300" sortable="custom" prop="vendorPayCondition">
                <template slot-scope="scope">
                  <div class="display_center">
                    <!--请输入-->
                    <el-select class="filter-item" v-model="scope.row.vendorPayCondition"  :placeholder="$t('scheduleManager.worksDetails.pleaseEnter')" style="flex: 1">
                      <el-option v-for="item in paymentTypeList" :key="item.value" :label="item.label" :value="item.value"></el-option>
                    </el-select>
                    <el-input :maxlength="100" v-if="scope.row.vendorPayCondition === 'other'" v-model="scope.row.vendorPayConditionText" :placeholder="$t('scheduleManager.worksDetails.pleaseEnter')" clearable class="filter-item" style="flex: 2"></el-input>
                  </div>
                </template>
              </el-table-column>
            </el-table-column>
            <el-table-column align="center" :label="projectVendorVo.vendorPerformanceBondContent">
              <!--廠商履約保證金需求-->
              <el-table-column align="center" :label="$t('scheduleManager.worksDetails.vendorPerformanceBondContent')" width="220" sortable="custom" prop="vendorPerformanceBondContent">
                <template slot-scope="scope">
                  <yt-select :clearable="true" @selectedChange="(val)=>setVendorPerformanceBondContent(scope.row,val)" v-model="scope.row.vendorPerformanceBondContent" :listData="vendorPerformanceBondContentList"></yt-select>
                </template>
              </el-table-column>
            </el-table-column>
            <el-table-column align="center" :label="projectVendorVo.vendorPerformanceBondMoney">
              <!--廠商履約保證金金額-->
              <el-table-column align="center" :label="$t('scheduleManager.worksDetails.vendorPerformanceBondMoney')" width="160" sortable="custom" prop="vendorPerformanceBondMoney">
                <template slot-scope="scope">
                  <div v-check-submit tabindex="0">
                    <!--请输入内容-->
                    <el-input :maxlength="100" style="display: none" type="number" :placeholder="$t('placeholder.content')" size="small" v-model="scope.row.vendorPerformanceBondMoney"></el-input>
                    <div class="box" v-format="'#,##0'" :placeholder="$t('placeholder.content')">{{ scope.row.vendorPerformanceBondMoney }}</div>
                  </div>
                </template>
              </el-table-column>
            </el-table-column>

            <el-table-column align="center" :label="'('+projectVendorVo.performanceBondExpireDateIs+')'+projectVendorVo.performanceBondExpireDate">
              <!--履約保證金到期日-->
              <el-table-column align="center" :label="$t('scheduleManager.worksDetails.performanceBondExpireDate')" width="220" sortable="custom" prop="performanceBondExpireDate">
                <template slot-scope="scope">
                  <div class="display_center">
                    <el-checkbox style="margin-right: 10px" true-label="1" label="0" false-label="0" v-model="scope.row.performanceBondExpireDateIs">N/A</el-checkbox>
                    <el-date-picker v-if="scope.row.performanceBondExpireDateIs !== '1'" v-model="scope.row.performanceBondExpireDate" class="dateTime yt-table-picker" type="date" :value-format="format" :format="format" :placeholder="$t('scheduleManager.worksDetails.pleaseEnter')"/>
                  </div>
                </template>
              </el-table-column>
            </el-table-column>

            <el-table-column align="center" :label="projectVendorVo.vendorExpectedFinishDate">
              <!--廠商預計完工日-->
              <el-table-column align="center" :label="$t('scheduleManager.worksDetails.vendorExpectedFinishDate')" width="220" sortable="custom" prop="vendorExpectedFinishDate">
                <template slot-scope="scope">
                  <el-date-picker v-model="scope.row.vendorExpectedFinishDate" class="dateTime yt-table-picker" type="date" :value-format="format" :format="format" :placeholder="$t('scheduleManager.worksDetails.pleaseEnter')"/>
                </template>
              </el-table-column>
            </el-table-column>
            <el-table-column align="center" :label="projectVendorVo.vendorRealityFinishDate">
              <!--廠商實際完工日-->
              <el-table-column align="center" :label="$t('scheduleManager.worksDetails.vendorRealityFinishDate')" width="220" sortable="custom" prop="vendorRealityFinishDate">
                <template slot-scope="scope">
                  <el-date-picker v-model="scope.row.vendorRealityFinishDate" class="dateTime yt-table-picker" type="date" :value-format="format" :format="format" :placeholder="$t('scheduleManager.worksDetails.pleaseEnter')"/>
                </template>
              </el-table-column>
            </el-table-column>
            <el-table-column align="center" :label="'('+projectVendorVo.catalogueIs+')'+projectVendorVo.catalogue">
              <!--型錄-->
              <el-table-column align="center" :label="$t('scheduleManager.worksDetails.catalogue')" width="220" sortable="custom" prop="catalogue">
                <template slot-scope="scope">
                  <div class="display_center">
                    <el-checkbox style="margin-right: 10px" true-label="1" label="0" false-label="0" v-model="scope.row.catalogueIs">N/A</el-checkbox>
                    <el-date-picker v-if="scope.row.catalogueIs !== '1'" v-model="scope.row.catalogue" class="dateTime yt-table-picker" type="date" :value-format="format" :format="format" :placeholder="$t('scheduleManager.worksDetails.pleaseEnter')"/>
                  </div>
                </template>
              </el-table-column>
            </el-table-column>
            <el-table-column align="center" :label="'('+projectVendorVo.declareDateIs+')'+projectVendorVo.declareDate">
              <!--進口報關單-->
              <el-table-column align="center" :label="$t('scheduleManager.worksDetails.declareDate')" width="220" sortable="custom" prop="declareDate">
                <template slot-scope="scope">
                  <div class="display_center">
                    <el-checkbox style="margin-right: 10px" true-label="1" label="0" false-label="0" v-model="scope.row.declareDateIs">N/A</el-checkbox>
                    <el-date-picker v-if="scope.row.declareDateIs !== '1'" v-model="scope.row.declareDate" class="dateTime yt-table-picker" type="date" :value-format="format" :format="format" :placeholder="$t('scheduleManager.worksDetails.pleaseEnter')"/>
                  </div>
                </template>
              </el-table-column>
            </el-table-column>
            <el-table-column align="center" :label="'('+projectVendorVo.pictureDataIs+')'+projectVendorVo.pictureData">
              <!--圖資-->
              <el-table-column align="center" :label="$t('scheduleManager.worksDetails.pictureData')" width="220" sortable="custom" prop="pictureData">
                <template slot-scope="scope">
                  <div class="display_center">
                    <el-checkbox style="margin-right: 10px" true-label="1" label="0" false-label="0" v-model="scope.row.pictureDataIs">N/A</el-checkbox>
                    <el-date-picker v-if="scope.row.pictureDataIs !== '1'" v-model="scope.row.pictureData" class="dateTime yt-table-picker" type="date" :value-format="format" :format="format" :placeholder="$t('scheduleManager.worksDetails.pleaseEnter')"/>
                  </div>
                </template>
              </el-table-column>
            </el-table-column>
            <el-table-column align="center" :label="'('+projectVendorVo.operatingManualIs+')'+projectVendorVo.operatingManual">
              <!--操作手冊-->
              <el-table-column align="center" :label="$t('scheduleManager.worksDetails.operatingManual')" width="220" sortable="custom" prop="operatingManual">
                <template slot-scope="scope">
                  <div class="display_center">
                    <el-checkbox style="margin-right: 10px" true-label="1" label="0" false-label="0" v-model="scope.row.operatingManualIs">N/A</el-checkbox>
                    <el-date-picker v-if="scope.row.operatingManualIs !== '1'" v-model="scope.row.operatingManual" class="dateTime yt-table-picker" type="date" :value-format="format" :format="format" :placeholder="$t('scheduleManager.worksDetails.pleaseEnter')"/>
                  </div>
                </template>
              </el-table-column>
            </el-table-column>
            <el-table-column align="center" :label="'('+projectVendorVo.factoryCertificateIs+')'+projectVendorVo.factoryCertificate">
              <!--出廠證明-->
              <el-table-column align="center" :label="$t('scheduleManager.worksDetails.factoryCertificate')" width="220" sortable="custom" prop="factoryCertificate">
                <template slot-scope="scope">
                  <div class="display_center">
                    <el-checkbox style="margin-right: 10px" true-label="1" label="0" false-label="0" v-model="scope.row.factoryCertificateIs">N/A</el-checkbox>
                    <el-date-picker v-if="scope.row.factoryCertificateIs !== '1'" v-model="scope.row.factoryCertificate" class="dateTime yt-table-picker" type="date" :value-format="format" :format="format" :placeholder="$t('scheduleManager.worksDetails.pleaseEnter')"/>
                  </div>
                </template>
              </el-table-column>
            </el-table-column>
            <el-table-column align="center" :label="'('+projectVendorVo.testReportIs+')'+projectVendorVo.testReport">
              <!--廠測報告-->
              <el-table-column align="center" :label="$t('scheduleManager.worksDetails.testReport')" width="220" sortable="custom" prop="testReport">
                <template slot-scope="scope">
                  <div class="display_center">
                    <el-checkbox style="margin-right: 10px" true-label="1" label="0" false-label="0" v-model="scope.row.testReportIs">N/A</el-checkbox>
                    <el-date-picker v-if="scope.row.testReportIs !== '1'" v-model="scope.row.testReport" class="dateTime yt-table-picker" type="date" :value-format="format" :format="format" :placeholder="$t('scheduleManager.worksDetails.pleaseEnter')"/>
                  </div>
                </template>
              </el-table-column>
            </el-table-column>
            <el-table-column align="center" :label="'('+projectVendorVo.signFileDateIs+')'+projectVendorVo.signFileDate">
              <!--設備/材料簽收單日-->
              <el-table-column align="center" :label="$t('scheduleManager.worksDetails.signFileDate')" width="220" sortable="custom" prop="signFileDate">
                <template slot-scope="scope">
                  <div class="display_center">
                    <el-checkbox style="margin-right: 10px" true-label="1" label="0" false-label="0" v-model="scope.row.signFileDateIs">N/A</el-checkbox>
                    <el-date-picker v-if="scope.row.signFileDateIs !== '1'" v-model="scope.row.signFileDate" class="dateTime yt-table-picker" type="date" :value-format="format" :format="format" :placeholder="$t('scheduleManager.worksDetails.pleaseEnter')"/>
                  </div>
                </template>
              </el-table-column>
            </el-table-column>
            <el-table-column align="center" :label="projectVendorVo.signersignatory">
              <!--簽收人-->
              <el-table-column align="center" :label="$t('scheduleManager.worksDetails.signersignatory')" width="220" sortable="custom" prop="signersignatory">
                <template slot-scope="scope">
                  <el-autocomplete clearable v-model="scope.row.signersignatory" :fetch-suggestions="getSignersignatory" :placeholder="$t('scheduleManager.worksDetails.pleaseEnterContent')" @select="item => setSignersignatory(item, scope.row)"></el-autocomplete>
                  <el-input :maxlength="100" style="display: none" size="small" v-model="scope.row.signersignatoryId"></el-input>
                </template>
              </el-table-column>
            </el-table-column>
            <el-table-column align="center" :label="'('+projectVendorVo.warrantyFileDateIs+')'+projectVendorVo.warrantyFileDate">
              <!--保固文件交付日-->
              <el-table-column align="center" :label="$t('scheduleManager.worksDetails.warrantyFileDate')" width="220" sortable="custom" prop="warrantyFileDate">
                <template slot-scope="scope">
                  <div class="display_center">
                    <el-checkbox style="margin-right: 10px" true-label="1" label="0" false-label="0" v-model="scope.row.warrantyFileDateIs">N/A</el-checkbox>
                    <el-date-picker v-if="scope.row.warrantyFileDateIs !== '1'" v-model="scope.row.warrantyFileDate" class="dateTime yt-table-picker" type="date" :value-format="format" :format="format" :placeholder="$t('scheduleManager.worksDetails.pleaseEnter')"/>
                  </div>
                </template>
              </el-table-column>
            </el-table-column>
            <el-table-column align="center" :label="projectVendorVo.otherFileNameText">
              <!--其他文件名稱-->
              <el-table-column align="center" :label="$t('scheduleManager.worksDetails.otherFileNameText')" width="220" sortable="custom" prop="otherFileNameText">
                <template slot-scope="scope">
                  <div class="display_center">
                    <el-select clearable class="filter-item" v-model="scope.row.otherFileName"  :placeholder="$t('scheduleManager.worksDetails.pleaseEnter')">
                      <el-option v-for="item in otherFileNameList" :key="item.value" :label="item.label" :value="item.value"></el-option>
                    </el-select>
                    <el-input :maxlength="100" v-if="scope.row.otherFileName === 'other'" v-model="scope.row.otherFileNameText" :placeholder="$t('scheduleManager.worksDetails.pleaseEnter')" clearable class="filter-item"></el-input>
                  </div>
                </template>
              </el-table-column>
            </el-table-column>
            <el-table-column align="center" :label="'('+projectVendorVo.otherFileSendDateIs+')'+projectVendorVo.otherFileSendDate">
              <!--其他文件交付日-->
              <el-table-column align="center" :label="$t('scheduleManager.worksDetails.otherFileSendDate')" width="220" sortable="custom" prop="otherFileSendDate">
                <template slot-scope="scope">
                  <div class="display_center">
                    <el-checkbox style="margin-right: 10px" true-label="1" label="0" false-label="0" v-model="scope.row.otherFileSendDateIs">N/A</el-checkbox>
                    <el-date-picker v-if="scope.row.otherFileSendDateIs !== '1'" v-model="scope.row.otherFileSendDate" class="dateTime yt-table-picker" type="date" :value-format="format" :format="format" :placeholder="$t('scheduleManager.worksDetails.pleaseEnter')"/>
                  </div>
                </template>
              </el-table-column>
            </el-table-column>
            <el-table-column align="center" :label="'('+projectVendorVo.sendCheckFileDateIs+')'+projectVendorVo.sendCheckFileDate">
              <!--驗收文件交付日-->
              <el-table-column align="center" :label="$t('scheduleManager.worksDetails.sendCheckFileDate')" width="220" sortable="custom" prop="sendCheckFileDate">
                <template slot-scope="scope">
                  <div class="display_center">
                    <el-checkbox style="margin-right: 10px" true-label="1" label="0" false-label="0" v-model="scope.row.sendCheckFileDateIs">N/A</el-checkbox>
                    <el-date-picker v-if="scope.row.sendCheckFileDateIs !== '1'" v-model="scope.row.sendCheckFileDate" class="dateTime yt-table-picker" type="date" :value-format="format" :format="format" :placeholder="$t('scheduleManager.worksDetails.pleaseEnter')"/>
                  </div>
                </template>
              </el-table-column>
            </el-table-column>
            <el-table-column align="center" :label="projectVendorVo.vendorAcceptanceDate">
              <!--廠商驗收日-->
              <el-table-column align="center" :label="$t('scheduleManager.worksDetails.vendorAcceptanceDate')" width="220" sortable="custom" prop="vendorAcceptanceDate">
                <template slot-scope="scope">
                  <el-date-picker v-model="scope.row.vendorAcceptanceDate" class="dateTime yt-table-picker" type="date" :value-format="format" :format="format" :placeholder="$t('scheduleManager.worksDetails.pleaseEnter')"/>
                </template>
              </el-table-column>
            </el-table-column>
            <el-table-column align="center" :label="projectVendorVo.vendorWarrantyType">
              <!--廠商保固金類型-->
              <el-table-column align="center" :label="$t('scheduleManager.worksDetails.vendorWarrantyType')" width="220" sortable="custom" prop="vendorWarrantyType">
                <template slot-scope="scope">
                  <yt-select :clearable="true" @selectedChange="(val)=>setVendorWarrantyType(scope.row,val)" v-model="scope.row.vendorWarrantyType" :listData="vendorWarrantyTypeList"></yt-select>
                </template>
              </el-table-column>
            </el-table-column>
            <el-table-column align="center" :label="'('+projectVendorVo.vendorWarrantyStartDateIs+')'+projectVendorVo.vendorWarrantyStartDate">
              <!--廠商保固開始日-->
              <el-table-column align="center" :label="$t('scheduleManager.worksDetails.vendorWarrantyStartDate')" width="220" sortable="custom" prop="vendorWarrantyStartDate">
                <template slot-scope="scope">
                  <div class="display_center">
                    <el-checkbox style="margin-right: 10px" true-label="1" label="0" false-label="0" v-model="scope.row.vendorWarrantyStartDateIs">N/A</el-checkbox>
                    <el-date-picker v-if="scope.row.vendorWarrantyStartDateIs !== '1'" v-model="scope.row.vendorWarrantyStartDate" class="dateTime yt-table-picker" type="date" :value-format="format" :format="format" :placeholder="$t('scheduleManager.worksDetails.pleaseEnter')"/>
                  </div>
                </template>
              </el-table-column>
            </el-table-column>
            <el-table-column align="center" :label="'('+projectVendorVo.vendorWarrantyEndDateIs+')'+projectVendorVo.vendorWarrantyEndDate">
              <!--廠商保固截止日-->
              <el-table-column align="center" :label="$t('scheduleManager.worksDetails.vendorWarrantyEndDate')" width="220" sortable="custom" prop="vendorWarrantyEndDate">
                <template slot-scope="scope">
                  <div class="display_center">
                    <el-checkbox style="margin-right: 10px" true-label="1" label="0" false-label="0"  v-model="scope.row.vendorWarrantyEndDateIs">N/A</el-checkbox>
                    <el-date-picker v-if="scope.row.vendorWarrantyEndDateIs !== '1'" v-model="scope.row.vendorWarrantyEndDate" class="dateTime yt-table-picker" type="date" :value-format="format" :format="format" :placeholder="$t('scheduleManager.worksDetails.pleaseEnter')"/>
                  </div>
                </template>
              </el-table-column>
            </el-table-column>
            <el-table-column align="center" :label="'('+projectVendorVo.vendorWarrantyReturnDateIs+')'+projectVendorVo.vendorWarrantyReturnDate">
              <!--廠商保固金退回日-->
              <el-table-column align="center" :label="$t('scheduleManager.worksDetails.vendorWarrantyReturnDate')" width="220" sortable="custom" prop="vendorWarrantyReturnDate">
                <template slot-scope="scope">
                  <div class="display_center">
                    <el-checkbox style="margin-right: 10px" true-label="1" label="0" false-label="0" v-model="scope.row.vendorWarrantyReturnDateIs">N/A</el-checkbox>
                    <el-date-picker v-if="scope.row.vendorWarrantyReturnDateIs !== '1'" v-model="scope.row.vendorWarrantyReturnDate" class="dateTime yt-table-picker" type="date" :value-format="format" :format="format" :placeholder="$t('scheduleManager.worksDetails.pleaseEnter')"/>
                  </div>
                </template>
              </el-table-column>
            </el-table-column>
            <el-table-column align="center" :label="projectVendorVo.vendorType">
              <!--廠商評鑑表-->
              <el-table-column align="center" :label="$t('scheduleManager.worksDetails.vendorType')" width="220" sortable="custom" prop="vendorType">
                <template slot-scope="scope">
                  <!-- "编辑廠商評鑑" : "选择厂商类型"  -->
                  <el-checkbox style="margin-right: 10px" true-label="1" label="0" false-label="0" v-model="scope.row.vendorTypeIs">N/A</el-checkbox>
                  <div v-if="!scope.row.vendorTypeIs || scope.row.vendorTypeIs !== '1'" @click="editGoTo(scope.row)" style="width: 100px;display:inline-block;cursor: pointer;">
                    {{ scope.row.vendorType ? $t('scheduleManager.worksDetails.editVendorType') : $t('scheduleManager.worksDetails.selectVendorType') }}
                  </div>
                </template>
              </el-table-column>
            </el-table-column>
            <el-table-column align="center" :label="projectVendorVo.vendorAppraiseDate">
              <!--廠商評鑑表日-->
              <el-table-column align="center" :label="$t('scheduleManager.worksDetails.vendorAppraiseDate')" width="220" sortable="custom" prop="vendorAppraiseDate">
                <template slot-scope="scope">
                  <el-date-picker v-model="scope.row.vendorAppraiseDate" class="dateTime yt-table-picker" type="date" disabled :value-format="format" :format="format" :placeholder="$t('scheduleManager.worksDetails.pleaseEnter')"/>
                </template>
              </el-table-column>
            </el-table-column>
          </el-table>
          <!--<div style="height: 20px;"></div>-->
        </div>
        <div class="pagination-container" style="margin:0 20px 10px">
          <el-pagination @size-change="handleSizeVendorChange" @current-change="handleCurrentVendorChange" background :hide-on-single-page="false" :current-page.sync="vendorCurrentPage" :page-sizes="[10, 20, 30, 50, 100, 200]" :page-size="vendorPageSize" layout="total, sizes, prev, pager, next, jumper" :total="vendorListLength"></el-pagination>
        </div>
      </div>

      <!-- 5、付款作业 -->
      <div class="yt-data-list">
        <div class="yt-list-title">
          <span>{{$t('scheduleManager.worksDetails.payWork')}}</span>
        </div>
        <div class="yt-list-content">
          <div class="list-operation">
            <!--新增-->
            <div class="yt-btn yt-btn-ys" @click="paymentAdd">{{ $t("button.new") }}</div>
            <!--删除-->
            <div class="yt-btn yt-ml8" @click="paymentDelete('del')">{{ $t("button.delete") }}</div>
            <div style="width:260px;display: inline-block;margin-left: 12px;">
              <el-input v-model="likeVendor2" :placeholder="$t('scheduleManager.progressList.eneterVendorPoNoPlaceholder')" clearable></el-input>
            </div>
            <div class="yt-btn yt-btn-ys" style="margin-left: 12px;" @click="queryVendor2">{{$t('scheduleManager.progressList.query')}}</div> <!--查询-->
          </div>
          <el-table border :data="filterVendor2?paymentList.filter(v => v.v).slice((paymentCurrentPage-1)*paymentPageSize,paymentCurrentPage*paymentPageSize):paymentList.slice((paymentCurrentPage-1)*paymentPageSize,paymentCurrentPage*paymentPageSize)" max-height="500" class="yt-table yt-temporary" @selection-change="paymentSelectionChange" @sort-change="sortDate3">
            <el-table-column align="center" fixed label="Sum">
              <el-table-column align="center" type="selection" width="60" />
              <el-table-column align="center" type="index" :label="$t('projectProcess.index.serialNumber')" width="60"/>
            </el-table-column>
            <el-table-column align="center" fixed :label="projectPaymentVo.vendorPoNo" width="160">
              <!--廠商PO單號(P)-->
              <el-table-column align="center" :label="$t('scheduleManager.worksDetails.vendorPoNoP')" width="160" sortable="custom" prop="vendorPoNo">
                <template slot-scope="scope">
                  <popover-select :progressId="projectProgress.id" @input="(val,item) => setVendorPoNo(item, scope.row)" selectType="vendorPo"
                    :placeholder="$t('scheduleManager.worksDetails.pleaseEnter')" valueObjName="vendorPoNo" v-model="scope.row.vendorPoNo"></popover-select>
                  <!-- <el-autocomplete clearable v-model="scope.row.vendorPoNo" :fetch-suggestions="getVendorPoNo" :placeholder="$t('scheduleManager.worksDetails.pleaseEnter')" @select="item => setVendorPoNo(item, scope.row)"></el-autocomplete> -->
                </template>
              </el-table-column>
            </el-table-column>
            <el-table-column align="center" fixed :label="projectPaymentVo.vendorName" width="130">
              <!--廠商簡稱(P)-->
              <el-table-column align="center" :label="$t('scheduleManager.worksDetails.vendorNameP')" width="100" sortable="custom" prop="vendorName">
                <template slot-scope="scope">
                  <el-input :maxlength="100" style="color:red;opacity:1" disabled v-model="scope.row.vendorName"></el-input>
                </template>
              </el-table-column>
            </el-table-column>
            <el-table-column align="center" :label="projectPaymentVo.expectedPaymentMoney">
              <!--預計付款金額-->
              <el-table-column align="center" :label="$t('scheduleManager.worksDetails.expectedPaymentMoney')" width="160" sortable="custom" prop="expectedPaymentMoney">
                <template slot-scope="scope">
                  <div v-check-submit tabindex="0">
                    <!--请输入内容-->
                    <el-input :maxlength="100" @change="expectedPaymentMoneyChange(scope.row)" style="display: none" type="number" :placeholder="$t('placeholder.content')" size="small" v-model="scope.row.expectedPaymentMoney"></el-input>
                    <div class="box" v-format="'#,##0'" :placeholder="$t('placeholder.content')">{{ scope.row.expectedPaymentMoney }}</div>
                  </div>
                </template>
              </el-table-column>
            </el-table-column>
            <el-table-column align="center" :label="projectPaymentVo.capitalProjectionDate">
              <!--未收發票預計付款日(資金預估)-->
              <el-table-column align="center" :label="$t('scheduleManager.worksDetails.capitalProjectionDate')" width="220" sortable="custom" prop="capitalProjectionDate">
                <template slot-scope="scope">
                  <yt-template-time v-model="scope.row.capitalProjectionDate"></yt-template-time>
                </template>
              </el-table-column>
            </el-table-column>
            <el-table-column align="center">
              <!--通知廠商開發票-->
              <el-table-column align="center" :label="$t('scheduleManager.worksDetails.tellVendorWriterInvoice')" width="220">
                <template slot-scope="scope">
                  <!--跳转通知廠商開發票-->
                  <div v-if="scope.row.id" @click="paymentGoTo(scope.row)" style="cursor: pointer;">{{$t('scheduleManager.worksDetails.toTellVendorWriterInvoice')}}</div>
                  <!--没有保存页面-->
                  <div v-else>{{$t('scheduleManager.worksDetails.noSavePage')}}</div>
                </template>
              </el-table-column>
            </el-table-column>
            <el-table-column align="center" :label="projectPaymentVo.vendorNoticeInvoiceDate">
              <!--通知廠商開發票日-->
              <el-table-column align="center" :label="$t('scheduleManager.worksDetails.vendorNoticeInvoiceDate')" width="220" sortable="custom" prop="vendorNoticeInvoiceDate">
                <template slot-scope="scope">
                  <yt-template-time v-model="scope.row.vendorNoticeInvoiceDate"></yt-template-time>
                </template>
              </el-table-column>
            </el-table-column>
            <el-table-column align="center" :label="projectPaymentVo.erpPayableNo">
              <!--ERP應付單號-->
              <el-table-column align="center" :label="$t('scheduleManager.worksDetails.erpPayableNo')" width="160" sortable="custom" prop="erpPayableNo">
                <template slot-scope="scope">
                  <!--请输入ERP應付單號-->
                  <el-input :maxlength="100" :placeholder="$t('scheduleManager.worksDetails.enterErpPayableNo')" v-model="scope.row.erpPayableNo" @blur="getQueryApaFile(scope.row)"></el-input>
                </template>
              </el-table-column>
            </el-table-column>
            <el-table-column align="center" :label="projectPaymentVo.paymentIs">
              <el-table-column align="center" :label="$t('scheduleManager.worksDetails.paymentIs')" width="100" sortable="custom" prop="paymentIs"><!--是否付款-->
                <template slot-scope="scope">
                  <el-checkbox :disabled="!scope.row.erpPayableNo" style="margin-right: 10px" true-label="1" false-label="0" v-model="scope.row.paymentIs"></el-checkbox>
                </template>
              </el-table-column>
            </el-table-column>
            <el-table-column align="center" :label="projectPaymentVo.vendorInvoiceDate">
              <!--廠商發票日-->
              <el-table-column align="center" :label="$t('scheduleManager.worksDetails.vendorInvoiceDate')" width="220" sortable="custom" prop="vendorInvoiceDate">
                <template slot-scope="scope">
                  <el-date-picker v-model="scope.row.vendorInvoiceDate" @change="vendorInvoiceDateChange(scope.row)" class="dateTime yt-table-picker" type="date" :value-format="format" :format="format"/>
                </template>
              </el-table-column>
            </el-table-column>
            <el-table-column align="center" :label="projectPaymentVo.vendorInvoiceNo">
              <!--廠商發票號碼-->
              <el-table-column align="center" :label="$t('scheduleManager.worksDetails.vendorInvoiceNo')" width="160" sortable="custom" prop="vendorInvoiceNo">
                <template slot-scope="scope">
                  <!--请输入廠商發票號碼-->
                  <el-input :maxlength="100" :placeholder="$t('scheduleManager.worksDetails.enterVendorInvoiceNo')" v-model="scope.row.vendorInvoiceNo" @blur="getQueryApaFile(scope.row)"></el-input>
                </template>
              </el-table-column>
            </el-table-column>
            <el-table-column align="center" :label="projectPaymentVo.vendorInvoiceMoney">
              <!--廠商發票金額-->
              <el-table-column align="center" :label="$t('scheduleManager.worksDetails.vendorInvoiceMoney')" width="160" sortable="custom" prop="vendorInvoiceMoney">
                <template slot-scope="scope">
                  <div v-check-submit tabindex="0">
                    <!--请输入内容-->
                    <el-input :maxlength="100" style="display: none" type="number" :placeholder="$t('placeholder.content')" size="small" v-model="scope.row.vendorInvoiceMoney"></el-input>
                    <div class="box" v-format="'#,##0'" :placeholder="$t('placeholder.content')">{{ scope.row.vendorInvoiceMoney }}</div>
                  </div>
                </template>
              </el-table-column>
            </el-table-column>
            <el-table-column align="center" :label="projectPaymentVo.expectedPaymentDate">
              <!--預計付款日-->
              <el-table-column align="center" :label="$t('scheduleManager.worksDetails.expectedPaymentDate')" width="220" sortable="custom" prop="expectedPaymentDate">
                <template slot-scope="scope">
                  <yt-template-time v-model="scope.row.expectedPaymentDate"></yt-template-time>
                </template>
              </el-table-column>
            </el-table-column>
            <el-table-column align="center" :label="projectPaymentVo.realityPaymentDate">
              <!--實際付款日-->
              <el-table-column align="center" :label="$t('scheduleManager.worksDetails.realityPaymentDate')" width="220" sortable="custom" prop="realityPaymentDate">
                <template slot-scope="scope">
                  <el-date-picker v-model="scope.row.realityPaymentDate" @change="realityPaymentDateChange(scope.row)" class="dateTime yt-table-picker" type="date" :value-format="format" :format="format" :placeholder="$t('scheduleManager.worksDetails.pleaseEnter')"/>
                </template>
              </el-table-column>
            </el-table-column>
            <el-table-column align="center" :label="projectPaymentVo.paymentMoney">
              <!--付款金額-->
              <el-table-column align="center" :label="$t('scheduleManager.worksDetails.paymentMoney')" width="220" sortable="custom" prop="paymentMoney">
                <template slot-scope="scope">
                  <div v-check-submit tabindex="0">
                    <!--请输入内容-->
                    <el-input :maxlength="100" style="display: none" type="number" :placeholder="$t('placeholder.content')" size="small" v-model="scope.row.paymentMoney"></el-input>
                    <div class="box" v-format="'#,##0'" :placeholder="$t('placeholder.content')">{{ scope.row.paymentMoney }}</div>
                  </div>
                </template>
              </el-table-column>
            </el-table-column>
            <el-table-column align="center" :label="projectPaymentVo.paymentRemark">
              <!--付款備註-->
              <el-table-column align="center" :label="$t('scheduleManager.worksDetails.paymentRemark')" width="220" sortable="custom" prop="paymentRemark">
                <template slot-scope="scope">
                  <!--请输入付款備註-->
                  <el-input :maxlength="200" :placeholder="$t('scheduleManager.worksDetails.enterPaymentRemark')" v-model="scope.row.paymentRemark"></el-input>
                </template>
              </el-table-column>
            </el-table-column>
          </el-table>
        </div>
        <div class="pagination-container" style="margin:0 20px 10px">
          <el-pagination @size-change="handleSizePaymentChange" @current-change="handleCurrentPaymentChange" background :hide-on-single-page="false" :current-page.sync="paymentCurrentPage" :page-sizes="[10, 20, 30, 50, 100, 200]" :page-size="paymentPageSize" layout="total, sizes, prev, pager, next, jumper" :total="paymentListLength"></el-pagination>
        </div>
      </div>
    </div>
    <div class="yt-all-btn save_buttom">
      <!--更新记录-->
      <div class="yt-btn yt-btn-ys" v-if="$route.query.progressId !== undefined" @click="record">
        {{$t('scheduleManager.worksDetails.updateRecord')}}
      </div>
      <!-- 保存提交 -->
      <div class="yt-btn yt-btn-ys yt-ml8" @click="preserve">{{ $t("button.preserve") }}</div>
    </div>
    <!--弹窗-->
    <!--请选择厂商管理类型-->
    <el-dialog :title="$t('scheduleManager.worksDetails.updateRecord')" :visible.sync="recordDialogTable" width="50%"><!--更新记录-->
      <div class="dialog">
        <el-table :data="recordList" :empty-text="$t('placeholder.emptyText')" label-width="100px" class="yt-table">
          <!--操作时间-->
          <el-table-column :label="$t('scheduleManager.worksDetails.createTime')"  width="100" prop="createTime" align="center" :formatter="formatter.formatTimes"/>
          <el-table-column :label="$t('scheduleManager.worksDetails.createName')"  width="100" prop="createName" align="center" /><!--操作人-->
          <el-table-column :label="$t('scheduleManager.worksDetails.contentZhCh')" prop="contentZhTc" align="center" /><!--操作日志-->
        </el-table>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="recordDialogTable = false">{{$t('scheduleManager.worksDetails.close')}}</el-button><!--关闭-->
      </span>
    </el-dialog>
    <el-dialog :title="$t('scheduleManager.worksDetails.vendorCheckTitle')" :visible.sync="dictDialogVisible" :close-on-click-modal="false" :showClose="true" class="yt-dialogForm-box">
      <!--厂商简称-->
      <div style="float:left;width: 50%">
        <span style="font-weight:bold">{{$t('scheduleManager.worksDetails.vendorName')}}: </span><span>{{ vendorNames }}</span>
      </div>
      <!--厂商工项-->
      <div style="float:left;width: 50%">
        <span style="font-weight:bold">{{$t('scheduleManager.worksDetails.vendorItem')}}: </span><span>{{ vendorItems }}</span>
      </div>
      <el-select v-model="editorDictText" :placeholder="$t('scheduleManager.worksDetails.vendorCheckPlaceholder')"><!--请选择厂商管理类型-->
        <el-option :label="$t('scheduleManager.worksDetails.vendorCheckProject')" value="GC"></el-option><!--厂商评鉴管理（工程类）-->
        <el-option :label="$t('scheduleManager.worksDetails.vendorCheckMaterial')" value="HC"></el-option><!--厂商评鉴（零件工程耗材）-->
      </el-select>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" class="yt-btn-ys" @click="editorDict()">{{$t('scheduleManager.worksDetails.sure')}}</el-button><!--确 定-->
        <el-button type="primary" class="yt-btn" style="margin-left: 0" @click="dictDialogVisible = false">{{$t('scheduleManager.worksDetails.cancel')}}</el-button><!--取 消-->
      </span>
    </el-dialog>
  </div>
</template>

<script>
  import YtSelect from '@/components/Yt-select/index.vue';
  import YtTemplate from '@/components/Yt-template/index.vue';
  import YtTemplateTime from '@/components/Yt-template/templateTime.vue';
  import YtTemplateTimeTwo from '@/components/Yt-template/templateTimeTwo.vue';
  import popoverSelect from '@/components/popover-select/index.vue';
  import { selectBuAndBg, selectBg } from '@/api/bu/index';
  /* listbgAndbu,, selectBu */
  import {
    getUserInfoByName,
    queryBySystemType,
    saveDetail,
    queryDetail,
    selectByProgressId,
    queryByExample,
    queryApaFile,
    handleTodo,
    queryARMoney,
    queryAPMoney
  } from '@/api/scheduleManager/worksDetails';
  import formatter from '@/utils/formatter';
  import store from '@/store'
  export default {
    name: 'worksDetails',
    components: {
      YtSelect,
      YtTemplateTimeTwo,
      YtTemplateTime,
      YtTemplate,
      popoverSelect
    },
    props: {
      format: {
        // 时间格式
        type: String,
        default: 'yyyy-MM-dd'
      }
    },
    data() {
      return {
        bu: '',
        bg: '',
        buId: '',
        buList: [],
        bgList: [],
        vendorListLength: 0,
        paymentListLength: 0,
        filterVendor: false,
        filterVendor2: false, // 查询后是否有结果
        likeVendor: '', // 厂商管理查询
        likeVendor2: '', // 厂商管理查询
        isPreserve: true,
        isPreserve2: true,
        vendorNames: '', // 厂商简称
        vendorItems: '', // 厂商工项
        tableName: '',
        payStatusFla: 0, // 付款狀態
        projectType: 0, // 專案狀態
        vendorListFla: 0,
        receivablesMoneySum: 0, // 收款金额  总和
        vendorPoMoneySum: 0, // 厂商PO金额  总和
        finishMoneyText: '',
        vendorNameList: [],
        id: '',
        signersignatoryList: [],
        editVendorIndex: null,
        editorDictText: '',
        dictDialogVisible: false,
        projectProgressData: {},
        projectProgress: {},
        basicList: [],
        contract: [],
        engineering: [],
        dataTemplateList: [],
        listAll: this.$store.getters.allDic,
        listMapAll: this.$store.getters.allMapDic,
        tableKey: 0,
        listLoading: false,
        NorY: this.$store.getters.allDic.NorY,
        paymentTypeList: this.$store.getters.allDic.paymentType,
        vendorPerformanceBondContentList: this.$store.getters.allDic
          .vendorPerformanceBondContent,
        vendorWarrantyTypeList: this.$store.getters.allDic.vendorWarrantyType,
        otherFileNameList: this.$store.getters.allDic.otherFileName,
        selectionList: [],
        list: [],
        vendorSelectionList: [],
        vendorList: [],
        paymentSelectionList: [],
        paymentList: [],
        recordDialogTable: false,
        recordList: [],
        formatter,
        projectRequestFundsVo: {},
        projectVendorVo: {},
        projectPaymentVo: {},
        requestCurrentPage: 1, // 当前页码
        requestPageSize: 10, // 每页的数据条数
        vendorCurrentPage: 1, // 当前页码
        vendorPageSize: 10, // 每页的数据条数
        paymentCurrentPage: 1, // 当前页码
        paymentPageSize: 10, // 每页的数据条数
        /**
         * bug 865 mingde
         */
        requestList: [], // 请款列表暂存
        handleList: [] // 应付列表暂存
      };
    },
    created() {
      /* if (!this.$route.query.progressId) {
        this.projectProgress.payStatus = 3
      } */
    },
    mounted() {
      this.getBu();
      this.getBg();
      this.id = this.$route.query.progressId || 'addWorks'
      this.projectProgress.systemType = 'A'
      if (!this.$route.query.progressId) { // 新建，默认没有付款资料
        this.$set(this.projectProgress, 'payStatus', '3')
      }
      this.getInit();
      this.getUserInfo();
    },
    methods: {
      getBg() {
        selectBg().then(res => {
          this.bgList = res.data
        });
      },
      setBu(val, row) {
        for (let i = 0; i < this.buList.length; i++) {
          if (this.buList[i].bu === val) {
            row.buId = this.buList[i].id;
            row.bu = this.buList[i].bu;
            row.bg = this.buList[i].bg;
            break;
          }
        }
      },
      getBu() {
        // 获取bu下拉选项
        selectBuAndBg().then(res => {
          this.buList = res.data
        });
      },
      // 查询厂商管理
      queryVendor() {
        this.filterVendor = false
        for (let i = 0; i < this.vendorList.length; i++) {
          // 设置显示的数据
          const vendorPoNo = this.vendorList[i].vendorPoNo || ''
          const vendorName = this.vendorList[i].vendorName || ''
          if (this.likeVendor && (vendorPoNo.includes(this.likeVendor) || vendorName.includes(this.likeVendor))) {
            this.vendorList[i].v = true
            this.filterVendor = true
          } else {
            this.vendorList[i].v = false
          }
        }
        // 计算 projectVendorVo中每一项的值
        let targetList = this.vendorList
        if (this.filterVendor) {
          targetList = this.vendorList.filter(v => v.v);
        }
        this.vendorListLength = targetList.length
        // is是括号里的,表示N/A的个数; 没有is的是括号外的,是真正有值的个数
        const result = {
          catalogue: 0,
          catalogueIs: 0,
          declareDate: 0,
          declareDateIs: 0,
          factoryCertificate: 0,
          factoryCertificateIs: 0,
          operatingManual: 0,
          operatingManualIs: 0,
          otherFileSendDate: 0,
          otherFileSendDateIs: 0,
          performanceBondExpireDate: 0,
          performanceBondExpireDateIs: 0,
          pictureData: 0,
          pictureDataIs: 0,
          sendCheckFileDate: 0,
          sendCheckFileDateIs: 0,
          signFileDate: 0,
          signFileDateIs: 0,
          // signersignatoryId: 0,
          testReport: 0,
          testReportIs: 0,
          vendorAcceptanceDate: 0,
          vendorAcceptanceDateIs: 0,
          vendorAppraiseDate: 0,
          vendorAppraiseDateIs: 0,
          vendorExpectedFinishDate: 0,
          vendorExpectedFinishDateIs: 0,
          vendorOfferMoney: 0,
          vendorPerformanceBondMoney: 0,
          vendorPoMoney: 0,
          vendorRealityFinishDate: 0,
          vendorRealityFinishDateIs: 0,
          vendorWarrantyEndDate: 0,
          vendorWarrantyEndDateIs: 0,
          vendorWarrantyReturnDate: 0,
          vendorWarrantyReturnDateIs: 0,
          vendorWarrantyStartDate: 0,
          vendorWarrantyStartDateIs: 0,
          warrantyFileDate: 0,
          warrantyFileDateIs: 0
        }

        for (const m of targetList) {
          // let catalogue = 0
          if (m.catalogue && m.catalogueIs === '0') {
            result.catalogue++
          } else {
            result.catalogueIs++
          }
          // let catalogueIs = 0
          // let declareDate = 0
          // let declareDateIs = 0
          if (m.declareDate && m.declareDateIs === '0') {
            result.declareDate++
          } else {
            result.declareDateIs++
          }
          // let factoryCertificate = 0
          // let factoryCertificateIs = 0
          if (m.factoryCertificate && m.factoryCertificateIs === '0') {
            result.factoryCertificate++
          } else {
            result.factoryCertificateIs++
          }
          // let operatingManual = 0
          // let operatingManualIs
          if (m.operatingManual && m.operatingManualIs === '0') {
            result.operatingManual++
          } else {
            result.operatingManualIs++
          }
          // let otherFileSendDate
          // let otherFileSendDateIs
          if (m.otherFileSendDate && m.otherFileSendDateIs === '0') {
            result.otherFileSendDate++
          } else {
            result.otherFileSendDateIs++
          }
          // let performanceBondExpireDate = 0
          // let performanceBondExpireDateIs = 0
          if (m.performanceBondExpireDate && m.performanceBondExpireDateIs === '0') {
            result.performanceBondExpireDate++
          } else {
            result.performanceBondExpireDateIs++
          }
          // let pictureData = 0
          // let pictureDataIs = 0
          if (m.pictureData && m.pictureDataIs === '0') {
            result.pictureData++
          } else {
            result.pictureDataIs++
          }
          // let sendCheckFileDate = 0
          // let sendCheckFileDateIs = 0
          if (m.sendCheckFileDate && m.sendCheckFileDateIs === '0') {
            result.sendCheckFileDate++
          } else {
            result.sendCheckFileDateIs++
          }
          // let signFileDate = 0
          // let signFileDateIs = 0
          if (m.signFileDate && m.signFileDateIs === '0') {
            result.signFileDate++
          } else {
            result.signFileDateIs++
          }
          // let signersignatoryId = 0
          // let testReport = 0
          // let testReportIs = 0
          if (m.testReport && m.testReportIs === '0') {
            result.testReport++
          } else {
            result.testReportIs++
          }
          // let vendorAcceptanceDate = 0
          // let vendorAcceptanceDateIs = 0
          if (m.vendorAcceptanceDate && m.vendorAcceptanceDateIs === '0') {
            result.vendorAcceptanceDate++
          } else {
            result.vendorAcceptanceDateIs++
          }
          if (m.vendorAppraiseDate && m.vendorAppraiseDateIs === '0') {
            result.vendorAppraiseDate++
          } else {
            result.vendorAppraiseDateIs++
          }
          // let vendorExpectedFinishDate = 0
          // let vendorExpectedFinishDateIs = 0
          if (m.vendorExpectedFinishDate && m.vendorExpectedFinishDateIs === '0') {
            result.vendorExpectedFinishDate++
          } else {
            result.vendorExpectedFinishDateIs++
          }
          // let vendorOfferMoney = 0
          if (m.vendorOfferMoney) {
            result.vendorOfferMoney += m.vendorOfferMoney
          }
          // let vendorPerformanceBondMoney = 0
          if (m.vendorPerformanceBondMoney) {
            result.vendorPerformanceBondMoney += m.vendorPerformanceBondMoney
          }
          // let vendorPoMoney = 0
          if (m.vendorPoMoney) {
            result.vendorPoMoney += m.vendorPoMoney
          }
          // let vendorRealityFinishDate = 0
          // let vendorRealityFinishDateIs = 0
          if (m.vendorRealityFinishDate && m.vendorRealityFinishDateIs === '0') {
            result.vendorRealityFinishDate++
          } else {
            result.vendorRealityFinishDateIs++
          }
          // let vendorWarrantyEndDate = 0
          // let vendorWarrantyEndDateIs = 0
          if (m.vendorWarrantyEndDate && m.vendorWarrantyEndDateIs === '0') {
            result.vendorWarrantyEndDate++
          } else {
            result.vendorWarrantyEndDateIs++
          }
          // let vendorWarrantyReturnDate = 0
          // let vendorWarrantyReturnDateIs = 0
          if (m.vendorWarrantyReturnDate && m.vendorWarrantyReturnDateIs === '0') {
            result.vendorWarrantyReturnDate++
          } else {
            result.vendorWarrantyReturnDateIs++
          }
          // let vendorWarrantyStartDate = 0
          // let vendorWarrantyStartDateIs = 0
          if (m.vendorWarrantyStartDate && m.vendorWarrantyStartDateIs === '0') {
            result.vendorWarrantyStartDate++
          } else {
            result.vendorWarrantyStartDateIs++
          }
          // let warrantyFileDate = 0
          // let warrantyFileDateIs = 0
          if (m.warrantyFileDate && m.warrantyFileDateIs === '0') {
            result.warrantyFileDate++
          } else {
            result.warrantyFileDateIs++
          }
        }
        this.projectVendorVo = result
        // 转成字符串并加千分号
        Object.keys(this.projectVendorVo).forEach(key => {
          this.projectVendorVo[key] = String(this.projectVendorVo[key]).replace(/\d{1,3}(?=(\d{3})+(\.|$))/g, '$&,')
        })
      },
      // 查询厂商管理
      queryVendor2() {
        this.filterVendor2 = false
        for (let i = 0; i < this.paymentList.length; i++) {
          // 设置显示的数据
          const vendorPoNo = this.paymentList[i].vendorPoNo || ''
          const vendorName = this.paymentList[i].vendorName || ''
          if (this.likeVendor2 && (vendorPoNo.includes(this.likeVendor2) || vendorName.includes(this.likeVendor2))) {
            this.paymentList[i].v = true
            this.filterVendor2 = true
          } else {
            this.paymentList[i].v = false
          }
        }
        // 计算 projectPaymentVo中每一项的值
        let targetList = this.paymentList
        if (this.filterVendor2) {
          // 有筛选
          targetList = this.paymentList.filter(v => v.v);
        }
        this.paymentListLength = targetList.length
        let expectedPaymentMoney = 0
        let capitalProjectionDate = 0
        let vendorNoticeInvoiceDate = 0
        let vendorInvoiceDate = 0
        let vendorInvoiceMoney = 0
        let expectedPaymentDate = 0
        let realityPaymentDate = 0
        let paymentMoney = 0

        for (const m of targetList) {
          // expectedPaymentMoney 预计付款金额
          if (m.expectedPaymentMoney) {
            expectedPaymentMoney += m.expectedPaymentMoney
          }
          // capitalProjectionDate 未收发票预计付款日
          if (m.capitalProjectionDate) {
            capitalProjectionDate += 1
          }
          // vendorNoticeInvoiceDate
          if (m.vendorNoticeInvoiceDate) {
            vendorNoticeInvoiceDate += 1
          }
          // vendorInvoiceDate
          if (m.vendorInvoiceDate) {
            vendorInvoiceDate += 1
          }
          // vendorInvoiceMoney
          if (m.vendorInvoiceMoney) {
            vendorInvoiceMoney += m.vendorInvoiceMoney
          }
          // expectedPaymentDate
          if (m.expectedPaymentDate) {
            expectedPaymentDate += 1
          }
          // realityPaymentDate
          if (m.realityPaymentDate) {
            realityPaymentDate += 1
          }
          // paymentMoney
          if (m.paymentMoney) {
            paymentMoney += m.paymentMoney
          }
        }

        this.projectPaymentVo.expectedPaymentMoney = expectedPaymentMoney
        this.projectPaymentVo.capitalProjectionDate = capitalProjectionDate
        this.projectPaymentVo.vendorNoticeInvoiceDate = vendorNoticeInvoiceDate
        this.projectPaymentVo.vendorInvoiceDate = vendorInvoiceDate
        this.projectPaymentVo.vendorInvoiceMoney = vendorInvoiceMoney
        this.projectPaymentVo.expectedPaymentDate = expectedPaymentDate
        this.projectPaymentVo.realityPaymentDate = realityPaymentDate
        this.projectPaymentVo.paymentMoney = paymentMoney
        // 转成字符串并加千分号
        Object.keys(this.projectPaymentVo).forEach(key => {
          this.projectPaymentVo[key] = String(this.projectPaymentVo[key]).replace(/\d{1,3}(?=(\d{3})+(\.|$))/g, '$&,')
        })
      },
      // 廠商保固金類型
      setVendorWarrantyType(row, val) {
        if (val === '6') {
          row.vendorWarrantyStartDateIs = '1'
          row.vendorWarrantyEndDateIs = '1'
          row.vendorWarrantyReturnDateIs = '1'

          row.vendorWarrantyStartDate = null
          row.vendorWarrantyEndDate = null
          row.vendorWarrantyReturnDate = null
        } else {
          row.vendorWarrantyStartDateIs = '0'
          row.vendorWarrantyEndDateIs = '0'
          row.vendorWarrantyReturnDateIs = '0'
        }
      },
      // 履約保證金需求
      setVendorPerformanceBondContent(row, val) {
        if (val === '2') {
          row.vendorPerformanceBondMoney = 0
          row.performanceBondExpireDate = null
          row.performanceBondExpireDateIs = '1'
        } else {
          row.performanceBondExpireDateIs = '0'
        }
      },
      handleSizeRequestChange(val) {
        this.requestCurrentPage = 1;
        this.requestPageSize = val;
      },
      handleCurrentRequestChange(val) {
        this.requestCurrentPage = val;
      },
      handleSizeVendorChange(val) {
        this.vendorCurrentPage = 1;
        this.vendorPageSize = val;
      },
      handleCurrentVendorChange(val) {
        this.vendorCurrentPage = val;
      },
      handleSizePaymentChange(val) {
        this.paymentCurrentPage = 1;
        this.paymentPageSize = val;
      },
      handleCurrentPaymentChange(val) {
        this.paymentCurrentPage = val;
      },
      downloadAppraise() {
        if (!this.projectProgress.id) {
          this.$message.error(this.$t('scheduleManager.worksDetails.firstSaveInfo')) // 请先保存信息
          return
        }
        let isDownload = false
        for (let i = 0; i < this.vendorList.length; i++) {
          if (this.vendorList[i].vendorAppraiseDate) {
            isDownload = true
            break
          }
        }
        if (!isDownload) {
          this.$message.error(this.$t('scheduleManager.worksDetails.firstCheckVendor')) // 请先评鉴厂商
          return
        }
        this.downloadProgressFile()
      },
      downloadProgressFile() {
        const list = [];
        list.push(this.projectProgress.id)
        let str = ''; // 传参数
        str = 'ids=' + list + '&type=2&createBy=' + this.$store.getters.info.id;
        const a = document.createElement('a');
        const href = '/api/admin/excel/downloadProgressFile?' + str;
        a.download = Date.now();
        a.href = href;
        a.click();
      },
      // 请款作业的开发票金额
      requestFundsMoney(val) {
        if (val.invoiceDate) {
          val.invoiceMoney = val.requestFundsMoney
        } else {
          val.invoiceMoney = ''
        }

        if (val.realityReceivablesDate) {
          val.receivablesMoney = val.requestFundsMoney
        } else {
          val.receivablesMoney = ''
        }
      },
      // 预计付款金额
      expectedPaymentMoneyChange(val) {
        if (val.vendorInvoiceDate != null) {
          if (val.hasOwnProperty('expectedPaymentMoney')) {
            // 厂商发票金额 = 预计付款金额
            val.vendorInvoiceMoney = val.expectedPaymentMoney
          }
        } else {
          val.vendorInvoiceMoney = ''
        }


        if (val.realityPaymentDate != null) {
          if (val.hasOwnProperty('expectedPaymentMoney')) {
            val.paymentMoney = val.expectedPaymentMoney
          }
        } else {
          val.paymentMoney = ''
        }
        const newObj = {};
        Object.assign(newObj, {}, val);
        this.$set(this.paymentList, val.listIndex, newObj)
      },
      // 通知廠商開發票日
      vendorInvoiceDateChange(val) {
        if (val.vendorInvoiceDate != null) {
          if (val.hasOwnProperty('expectedPaymentMoney')) {
            // 厂商发票金额 = 预计付款金额
            val.vendorInvoiceMoney = val.expectedPaymentMoney
          }
        } else {
          val.vendorInvoiceMoney = ''
        }
        const newObj = {};
        Object.assign(newObj, {}, val);
        this.$set(this.paymentList, val.listIndex, newObj)
      },
      // 實際付款日
      realityPaymentDateChange(val) {
        if (val.realityPaymentDate != null) {
          if (val.hasOwnProperty('expectedPaymentMoney')) {
            val.paymentMoney = val.expectedPaymentMoney
          }
        } else {
          val.paymentMoney = ''
        }
        const newObj = {};
        Object.assign(newObj, {}, val);
        this.$set(this.paymentList, val.listIndex, newObj)
      },
      // 廠商PO單號(P)
      setVendorPoNo(item, row) {
        row.vendorName = item.vendorName
        row.vendorNo = item.vendorNo
        console.log(JSON.stringify(item))
        row.projectVendorId = item.vendorId
      },
      // 查询厂商信息
      setVendor(item, row) {
        row.vendorPoNo = item.vendorPoNo
        row.vendorId = item.id
        row.vendorNameOld = item.vendorShortName
        row.vendorNo = item.vendorNo
      },
      // 簽收人
      setSignersignatory(item, list) {
        list.signersignatoryId = item.id;
        // signersignatoryId
        // this.dataTemplate[listIndex].projectEngineer = item.name;
      },
      // 簽收人
      getSignersignatory(queryString, cb) {
        getUserInfoByName({ username: queryString }).then(res => {
          const userList = res.data.rows;
          for (let i = 0; i < userList.length; i++) {
            userList[i].value = userList[i].ename;
          }
          cb(userList);
        });
      },
      getUserInfo() {
        getUserInfoByName().then(res => {
          this.signersignatoryList = Object.assign([], res.data.rows);
        });
      },
      // 先找出res.data和this.list的交集 intersection
      // 在找出res.data和intersection的差集 differentSet
      // 在差集中differentSet中找到第一个进行以下是修改逻辑即可
      getAnotherOne(data) {
        // 先找出res.data和this.list的交集 intersection
        let intersetion = []
        intersetion = data.filter(x => {
          let type = false
          this.list.forEach(item => {
            // 如果发票号码和应收单号一致则返回
            if (x.oma10 === item.invoiceNo && x.oma01 === item.erpReceivablesNo) {
              type = true
            }
          })
          return type
        })
        if (intersetion.length === data.length) {
          return data[0]
        }
        // 在找出res.data和intersection的差集 differentSet
        let differntSet = []
        differntSet = data.filter(val => !intersetion.includes(val))
        if (differntSet.length > 0) {
          return differntSet[0]
        } else {
          return data[0]
        }
      },
      // 根据erp应收单号或者厂商发票号码查询
      getQueryByExample(val) {
        // console.log('根据erp应收单号或者厂商发票号码查询')
        const data = {
          oma01: val.erpReceivablesNo, // erp应收单号
          oma10: val.invoiceNo // 发票号码
        };
        queryByExample(data).then(res => {
          if (res.data && res.data.length > 0) {
            // 先找出res.data和this.list的交集 intersection
            // 在找出res.data和intersection的差集 differentSet
            // 在差集中differentSet中找到第一个进行以下是修改逻辑即可

            let result = {}
            const list = res.data
            if (list.length >= 2) {
              result = this.getAnotherOne(list)
            }
            if (list.length === 1) {
              result = list[0]
            }
            val.invoiceNo = result.oma10; // 发票号码
            val.erpReceivablesNo = result.oma01; // erp应收单号
            val.invoiceDate = result.oma09; // "开发票日期"
            val.requestIs = result.requestIs; // 是否请款
            if (result.requestIs && result.requestIs === '1') {
              // 若請款作業新增一筆資料，並有勾選分批收款，預計收款日應帶出未開發票預計收款日(資金預估)的日期
              // 實際收款日應先不帶出
              val.expectedReceivablesDate = val.capitalProjectionDate
              val.realityReceivablesDate = ''
            } else {
              val.expectedReceivablesDate = result.oma11; // "预计收款日
              val.realityReceivablesDate = result.ooa02; // "實際收款日
            }
            //  请款金额、发票金额(res.data.oma59)、实际收款金额完全一样
            if (val.invoiceDate) {
              // 发票金额"
              val.invoiceMoney = val.requestFundsMoney
            } else {
              val.invoiceMoney = ''
            }

            if (val.realityReceivablesDate) {
              // 实际收款金额
              val.receivablesMoney = val.requestFundsMoney
            } else {
              val.receivablesMoney = ''
            }
          }
          // 改变this.list中对应下标的数据
          const newObj = {};
          Object.assign(newObj, {}, val);
          this.$set(this.list, val.listIndex, newObj);
        });
      },
      // 先找出res.data和this.paymentList的交集 intersection
      // 在找出res.data和intersection的差集 differentSet
      // 在差集中differentSet中找到第一个进行以下是修改逻辑即可
      getAnotherOnes(data) {
        // 先找出res.data和this.paymentList的交集 intersection
        let intersetion = []
        intersetion = data.filter(x => {
          let type = false
          this.paymentList.forEach(item => {
            // 如果发票号码和应收单号一致则返回
            if (x.apa01 === item.erpPayableNo && x.apk03 === item.vendorInvoiceNo) {
              type = true
            }
          })
          return type
        })
        if (intersetion.length === data.length) {
          return data[0]
        }
        // 在找出res.data和intersection的差集 differentSet
        let differntSet = []
        differntSet = data.filter(val => !intersetion.includes(val))
        if (differntSet.length > 0) {
          return differntSet[0]
        } else {
          return data[0]
        }
      },
      getQueryApaFile(val) {
        const data = {
          apa01: val.erpPayableNo, // "ERP應付單號"
          apk03: val.vendorInvoiceNo // 廠商發票號碼
        };
        queryApaFile(data).then(res => {
          if (res.data && res.data.length > 0) {
            let result = {}
            const list = res.data
            if (list.length >= 2) {
              result = this.getAnotherOnes(list)
            }
            if (list.length === 1) {
              result = list[0]
            }
            // "ERP應付單號"
            if (result.apa01 && result.apa01.trim()) {
              val.erpPayableNo = result.apa01
            }
            // "廠商發票號碼"
            if (result.apk03 && result.apk03.trim()) {
              val.vendorInvoiceNo = result.apk03
            }
            // "厂商发票日"
            if (result.apk05) {
              val.vendorInvoiceDate = result.apk05;
            }
            // val.erpPayableNo = result.apa01 || val.erpPayableNo; // "ERP應付單號"
            // val.vendorInvoiceNo = result.apk03 || val.vendorInvoiceNo; // "廠商發票號碼"
            // val.vendorInvoiceDate = result.apk05; // "厂商发票日"
            if (val.vendorInvoiceDate && val.expectedPaymentMoney) {
              // 厂商发票金额 = 预计付款金额
              val.vendorInvoiceMoney = val.expectedPaymentMoney
            } else {
              val.vendorInvoiceMoney = ''
            }
            val.paymentIs = result.paymentIs; // 是否请款
            // val.vendorInvoiceMoney = res.data.apk08; // "厂商发票金额"

            if (result.paymentIs && result.paymentIs === '1') {
              // 若付款作業新增一筆資料，並有勾選分批收款，預計付款日應帶出未開發票預計付款日(資金預估)的日期
              // 實際付款日應先不帶出
              val.expectedPaymentDate = val.capitalProjectionDate
              val.realityPaymentDate = ''
            } else {
              val.expectedPaymentDate = result.apa12; // "预计付款日
              val.realityPaymentDate = result.apf02; // "实际付款日的
            }
            // 如果实际付款日有值，预计付款金额 = 付款金额
            if (val.realityPaymentDate && val.expectedPaymentMoney) {
              val.paymentMoney = val.expectedPaymentMoney
            } else {
              val.paymentMoney = ''
            }
          }
          const newObj = {};
          Object.assign(newObj, {}, val);
          this.$set(this.paymentList, val.listIndex, newObj);
        });
      },
      record() {
        if (this.projectProgress.id) {
          const obj = {
            progressId: this.projectProgress.id,
            orderBy: 'createTime',
            order: 'DESC'
          };
          selectByProgressId(obj).then(res => {
            this.recordList = res.data.rows;
            this.recordDialogTable = true;
          });
        }
      },
      paymentGoTo(row) {
        console.log(JSON.stringify(row))
        if (!row.vendorNo) {
          this.$message.error(this.$t('scheduleManager.worksDetails.tellVendorInvoceTips')) // 该付款作业未关联厂商信息,请先选择厂商
          return false
        }
        this.$router.push({
          path: '/progressManager/manufacturerTicket',
          query: { queryId: row.id, projectProgressId: this.projectProgress.id, vendorPoNo: row.vendorPoNo, vendorName: row.vendorName, vendorNo: row.vendorNo }
        });
      },
      editGoTo(row) {
        const id = row.id || '';
        const vendorNo = row.vendorNo || '';
        this.editVendorIndex = row.listIndex;
        const vendorType = row.vendorType || '';

        this.vendorNames = row.vendorName
        this.vendorItems = row.vendorItem

        if (row.vendorName === '' || row.vendorName === undefined) {
          this.$message.error(this.$t('scheduleManager.worksDetails.pleaseSelectVendor')) // 请选择厂商简称 pleaseSelectVendor
          return false
        }

        if (row.vendorName !== row.vendorNameOld) {
          this.$message.error(this.$t('scheduleManager.worksDetails.pleaseSelectCorrectVendor')) // 请选择正确的厂商简称 pleaseSelectCorrectVendor
          return false
        }
        if (vendorType) {
          if (vendorType === 'GC') {
            this.$router.push({
              path: '/progressManager/vendorEngineering',
              query: { queryId: id, progressId: this.projectProgress.id, item: row.vendorItem, start: this.projectProgress.actualCommencementDate, end: this.projectProgress.realityFinishDate, bu: this.projectProgress.bu, bg: this.projectProgress.bg }
            });
          } else if (vendorType === 'HC') {
            this.$router.push({
              path: '/progressManager/vendorConsumables',
              query: { queryId: id, progressId: this.projectProgress.id, vendorNo }
            });
          }
        } else {
          this.dictDialogVisible = true;
        }
      },
      editorDict() {
        if (this.editorDictText !== '') {
          this.vendorList[this.editVendorIndex].vendorType = this.editorDictText;
          this.dictDialogVisible = false;
          this.preserve();
          this.editGoTo(this.vendorList[this.editVendorIndex])
        } else {
          this.$message.error(this.$t('scheduleManager.worksDetails.pleaseSelectVendorType')); // 请选择厂商管理类型！
        }
      },
      selectedChange(val) {
        this.projectProgress.systemType = val
        this.setBlock();
      },
      async getInit() {
        const str = '/progressManager/worksDetails'
        if (this.$route.query.progressId || this.$store.getters.pageState[str] && this.$store.getters.pageState[str][this.id]) {
          // 如果是修改，等systemType返回之后，再初始化栏位
          await this.getData()
        }
        this.setBlock();
       

      console.log('========_'+this.projectType)
      console.log('this.projectProgress', this.projectProgress.id)
      if(null != this.projectProgress.id){
        saveProjectStatusDetail(this.projectProgress).then(res => {
        })
      }
      
      },
      setBlock() {
        this.basicList = [];
        this.contract = [];
        this.engineering = [];
        const data = {
          systemType: this.projectProgress.systemType
        };
        queryBySystemType(data).then(res => {
          if (res.data) {
            if (res.data.length > 0) {
              res.data.forEach(x => {
                const newObj = {};
                Object.assign(newObj, {}, x);
                if (x.type === '0') {
                  // 工务基本讯息
                  this.basicList.push(newObj);
                } else if (x.type === '1') {
                  // 合约内容
                  this.contract.push(newObj);
                } else if (x.type === '2') {
                  // 工程执行
                  this.engineering.push(newObj);
                }
              });
            }
          }
        });
        console.log('this.contract', this.contract)
      },
      getData() {   
        const str = '/progressManager/worksDetails'
        if (this.$store.getters.pageState[str] && this.$store.getters.pageState[str][this.id]) {
          const obj = this.$store.getters.pageState[str][this.id]
          this.projectProgress = obj.projectProgress
          if (!this.projectProgress.completedPercent) {
            if (this.projectProgress.realityFinishDate) {
              this.$set(this.projectProgress, 'completedPercent', 100)
            } else {
              this.$set(this.projectProgress, 'completedPercent', 0)
            }
          }
          for (let i = 0; i < this.buList.length; i++) {
            if (this.buList[i].bu === this.projectProgress.bu) {
              this.buId = this.buList[i].id;
              this.bu = this.buList[i].bu;
              this.bg = this.buList[i].bg;
              break;
            }
          }
          this.list = obj.list // 3、请款作业
          this.vendorList = obj.vendorList // 4、厂商管理
          this.vendorListLength = this.vendorList ? this.vendorList.length : 0
          this.paymentList = obj.paymentList // 5、付款作业
          this.paymentListLength = this.paymentList ? this.paymentList.length : 0
          this.projectRequestFundsVo = obj.projectRequestFundsVo
          this.projectVendorVo = obj.projectVendorVo
          this.projectPaymentVo = obj.projectPaymentVo
          return new Promise(resolve => {
            resolve();
          })
        } else {
          return new Promise(resolve => {
            console.log('jinlaile')
            if (this.$route.query.progressId) {
              const obj = {
                progressId: this.$route.query.progressId,
                userId: this.$store.getters.info.id
              }
              // 处理待办
              handleTodo(obj).then(res => {
                console.log(res)
              })
            }

            if (this.id && this.id !== 'addWorks') {
              queryDetail({ progressId: this.$route.query.progressId }).then(res => {
                this.list = [];
                this.vendorList = [];
                this.paymentList = [];

                if (res.data.projectRequestFundsList) {
                  this.list = res.data.projectRequestFundsList
                  for (let y = 0; y < this.list.length; y++) {
                    this.list[y].listIndex = y;
                  }
                }
                if (res.data.projectVendorList) {
                  this.vendorList = res.data.projectVendorList;
                  for (let y = 0; y < this.vendorList.length; y++) {
                    this.vendorList[y].vendorNameOld = this.vendorList[y].vendorName
                    this.vendorList[y].listIndex = y;
                  }
                  this.vendorListLength = this.vendorList.length
                }
                if (res.data.projectPaymentList) {
                  this.paymentList = res.data.projectPaymentList;
                  for (let y = 0; y < this.paymentList.length; y++) {
                    this.paymentList[y].listIndex = y;
                  }
                  this.paymentListLength = this.paymentList.length
                }
                if (res.data.projectProgress) {
                  this.projectProgress = res.data.projectProgress;
                  this.projectProgress.country = this.listMapAll.country[this.projectProgress.country];
                  this.projectProgress.projectNoOld = this.projectProgress.projectNo;
                  if (!this.projectProgress.completedPercent) {
                    if (this.projectProgress.realityFinishDate) {
                      this.$set(this.projectProgress, 'completedPercent', 100)
                    } else {
                      this.$set(this.projectProgress, 'completedPercent', 0)
                    }
                  }
                }

                this.projectRequestFundsVo = res.data.projectRequestFundsVo;
                this.projectVendorVo = res.data.projectVendorVo;
                this.projectPaymentVo = res.data.projectPaymentVo;
                Object.keys(this.projectRequestFundsVo).forEach(key => {
                  this.projectRequestFundsVo[key] = String(this.projectRequestFundsVo[key]).replace(/\d{1,3}(?=(\d{3})+(\.|$))/g, '$&,')
                })
                Object.keys(this.projectVendorVo).forEach(key => {
                  this.projectVendorVo[key] = String(this.projectVendorVo[key]).replace(/\d{1,3}(?=(\d{3})+(\.|$))/g, '$&,')
                })
                Object.keys(this.projectPaymentVo).forEach(key => {
                  this.projectPaymentVo[key] = String(this.projectPaymentVo[key]).replace(/\d{1,3}(?=(\d{3})+(\.|$))/g, '$&,')
                })
                for (let i = 0; i < this.buList.length; i++) {
                  if (this.buList[i].bu === this.projectProgress.bu) {
                    this.buId = this.buList[i].id;
                    this.bu = this.buList[i].bu;
                    this.bg = this.buList[i].bg;
                    break;
                  }
                }
                resolve();
              });
            }
          })
        }     
      },
      // 请款作业 新增
      newly() {
        const dataList = {
          listIndex: this.list.length,
          blockSeq: '',
          blockName: '',
          mustFill: '',
          systemType: '',
          systemType1: '',
          systemType2: '',
          systemType3: '',
          systemType4: ''
        };
        this.$set(this.list, this.list.length, dataList);
        // 跳最后一页
        this.requestCurrentPage = Math.ceil(this.list.length / this.requestPageSize);
      },
      // 请款作业 选择事件
      handleSelectionChange(val) {
        //  表格序号选中函数
        this.selectionList = val;
      },
      // 排序
      sortDate(column) {
        if (column.order) {
          this.formatter.sortByKey(this.list, column.prop, column.order)
        }
      },
      sortDate2(column) {
        if (column.order) {
          this.formatter.sortByKey(this.vendorList, column.prop, column.order)
        }
      },
      sortDate3(column) {
        if (column.order) {
          this.formatter.sortByKey(this.paymentList, column.prop, column.order)
        }
      },
      // 请款作业 删除
      handleDelete() {
        if (this.selectionList.length > 0) {
          this.selectionList.forEach(x => {
            this.list.splice(
              this.list.findIndex(item => item.listIndex === x.listIndex),
              1
            );
          });
          for (let y = 0; y < this.list.length; y++) {
            this.list[y].listIndex = y;
          }
        } else {
          this.$message.error(this.$t('scheduleManager.worksDetails.pleaseSelectToDelete')); // 请选择删除的列表！
        }
      },
      // 厂商管理 新增
      vendorAdd() {
        const dataList = {
          listIndex: this.vendorList.length,
          blockSeq: '',
          blockName: '',
          mustFill: '',
          systemType: '',
          systemType1: '',
          systemType2: '',
          systemType3: '',
          systemType4: '',
          vendorWarrantyStartDateIs: '',
          vendorWarrantyEndDateIs: '',
          vendorWarrantyReturnDateIs: '',
          vendorWarrantyStartDate: null,
          vendorWarrantyEndDate: null,
          vendorWarrantyReturnDate: null,
          buId: this.buId,
          bu: this.bu,
          bg: this.bg
        };
        if (this.filterVendor && this.filterVendor === true) {
          dataList.v = true
        }
        this.$set(this.vendorList, this.vendorList.length, dataList);
        this.vendorCurrentPage = Math.ceil(this.vendorList.length / this.vendorPageSize);

        if (this.filterVendor && this.filterVendor === true) {
          let targetList = this.vendorList
          // 有筛选
          targetList = this.vendorList.filter(v => v.v);
          this.vendorListLength = targetList.length
        } else {
          this.vendorListLength = this.vendorList.length
        }
      },
      // 厂商管理 选择事件
      vendorSelectionChange(val) {
        //  表格序号选中函数
        this.vendorSelectionList = val;
      },
      // 厂商管理 删除
      vendorDelete() {
        if (this.vendorList.length > 0) {
          this.vendorSelectionList.forEach(x => {
            this.vendorList.splice(
              this.vendorList.findIndex(item => item.listIndex === x.listIndex),
              1
            );
          });
          for (let y = 0; y < this.vendorList.length; y++) {
            this.vendorList[y].listIndex = y;
          }
        } else {
          this.$message.error(this.$t('scheduleManager.worksDetails.pleaseSelectToDelete')); // '请选择删除的列表！
        }
      },
      // 付款作业 新增
      paymentAdd() {
        const dataList = {
          listIndex: this.paymentList.length,
          blockSeq: '',
          blockName: '',
          mustFill: '',
          systemType: '',
          systemType1: '',
          systemType2: '',
          systemType3: '',
          systemType4: ''
        };
        if (this.filterVendor2 && this.filterVendor2 === true) {
          dataList.v = true
        }
        this.$set(this.paymentList, this.paymentList.length, dataList);
        this.paymentCurrentPage = Math.ceil(this.paymentList.length / this.paymentPageSize);
        if (this.filterVendor2 && this.filterVendor2 === true) {
          let targetList = this.paymentList
          // 有筛选
          targetList = this.paymentList.filter(v => v.v);
          this.paymentListLength = targetList.length
        } else {
          this.paymentListLength = this.paymentList.length
        }
      },
      // 付款作业 选择事件
      paymentSelectionChange(val) {
        //  表格序号选中函数
        this.paymentSelectionList = val;
      },
      // 付款作业 删除
      paymentDelete() {
        if (this.paymentList.length > 0) {
          this.paymentSelectionList.forEach(x => {
            this.paymentList.splice(
              this.paymentList.findIndex(item => item.listIndex === x.listIndex),
              1
            );
          });
          for (let y = 0; y < this.paymentList.length; y++) {
            this.paymentList[y].listIndex = y;
          }
        } else {
          this.$message.error(this.$t('scheduleManager.worksDetails.pleaseSelectToDelete')); // '请选择删除的列表！
        }
      },
      async preserve() {
        const str = '/progressManager/worksDetails'
        let dataList = [];
        dataList = dataList.concat(
          this.basicList,
          this.contract,
          this.engineering
        );
        if (this.projectProgress.performanceBondContent === '1') {
          if (!this.projectProgress.hasOwnProperty('performanceBondMoney') || this.projectProgress.performanceBondMoney === '') {
            this.$message.error(
              this.$t('scheduleManager.worksDetails.enterPerformanceBondMoney')
            ); // 请填写 履約保證金金額
            return false;
          }
        }
        if (this.projectProgress.isInsure === '1') {
          if (this.projectProgress.hasOwnProperty('insureDate')) {
            if (this.projectProgress.insureDate == null) {
              this.$message.error(
                this.$t('scheduleManager.worksDetails.eneterInsureDate')
              ); // '请填写 保險日'
              return false;
            }
          } else {
            this.$message.error(
              this.$t('scheduleManager.worksDetails.eneterInsureDate')
            ); // '请填写 保險日'
            return false;
          }
        }
        // 判断 是否是必填项
        let fla = false
        dataList.forEach(x => {
          if (x.blockCode === 'projectNo') {
            if (this.projectProgress.hasOwnProperty('projectNo')) {
              if (this.projectProgress.projectNo && this.projectProgress.projectNoOld &&
              this.projectProgress.projectNoOld !== this.projectProgress.projectNo) {
                this.$message.error(
                  this.$t('scheduleManager.worksDetails.enterProjectNoTips')
                ); // '请填写 正确的 專案編號 '
                fla = true
              }
            }
          }
          if (x.mustFill === '1') {
            if (this.projectProgress.hasOwnProperty(x.blockCode)) {
              // 请填写
              this.$message.error(
                this.$t('scheduleManager.worksDetails.pleaseEnterTips') + this.listMapAll.nameColumn[x.blockCode] + '"'
              );
              fla = true
            }
          }
        });
        if (fla) {
          return true;
        }
        // 校验 收款备注的长度,厂商工项,付款备注 receivable_remark
        /* if (this.list && this.list.length > 0) {
          for (let i = 0; i < this.list.length; i++) {
            const j = i + 1;
            if (this.list[i].receivableRemark && this.list[i].receivableRemark > 500) {
              this.$message.error(this.$t('scheduleManager.worksDetails.receiveWorks') + this.$t('myDailyDetails.message.ordinalNumbers') + j + this.$t('myDailyDetails.message.columnName') + '「'+ this.$t('scheduleManager.worksDetails.receivableRemark') +'」' + this.$t('myDailyDetails.message.moreThan') + 500 + this.$t('myDailyDetails.message.moreThanTwo'))
              return false;
            }
          }
        } */

        // 厂商工项 vendor_pay_condition_text
        /* if (this.vendorList && this.list.vendorList > 0) {
          for (let i = 0; i < this.vendorList.length; i++) {
            const j = i + 1;
            if (this.vendorList[i].vendorPayConditionText && this.vendorList[i].vendorPayConditionText > 500) {
              this.$message.error(this.$t('scheduleManager.worksDetails.vendorManagement') + this.$t('myDailyDetails.message.ordinalNumbers') + j + this.$t('myDailyDetails.message.columnName') + '「' + this.$t('scheduleManager.worksDetails.vendorPayCondition') + '」' + this.$t('myDailyDetails.message.moreThan') + 500 + this.$t('myDailyDetails.message.moreThanTwo'))
              return false;
            }
          }
        }
*/
        // 付款备注 payment_remark
        /* if (this.paymentList && this.list.paymentList > 0) {
          for (let i = 0; i < this.list.length; i++) {
            const j = i + 1;
            if (this.paymentList[i].paymentRemark && this.paymentList[i].paymentRemark > 500) {
              this.$message.error(this.$t('scheduleManager.worksDetails.payWork') + this.$t('myDailyDetails.message.ordinalNumbers') + j + this.$t('myDailyDetails.message.columnName') + '「' + this.$t('scheduleManager.worksDetails.paymentRemark') + '」' + this.$t('myDailyDetails.message.moreThan') + 500 + this.$t('myDailyDetails.message.moreThanTwo'))
              return false;
            }
          }
        } */


        const data = {
          projectProgress: this.projectProgress,
          projectRequestFundsList: this.list, // 3、请款作业
          projectVendorList: this.vendorList, // 4、厂商管理
          projectPaymentList: this.paymentList // 5、付款作业
        };
        /* 請款作業每一筆ERP應收單號對應的請款金額之和必須等於ERP應收單號的金額 */
        /* 请款作业每一笔ERP应收单号对应的请款金额之和必须等于ERP应收单号的金额*/
        /* the total of Request Payment Money of the Payment must equals the Request money of ERP!*/
        // if (this.list && this.list.length > 0) {
        //   await this.ARMoneyCheck(this.list)
        //   console.log('this.ARMoneyCheck(this.list)', this.isPreserve)
        //   if (!this.isPreserve) {
        //     return
        //   }
        // }
        /* 付款作業的預計付款金額之和必須等於該ERP應付單號對應的金額 */
        /* 付款作业的预计付款金额之和必须等于该ERP应付单号对应的金额 */
        /* the total of Excepted Payment Money of the Payment must equals the payment money of ERP!*/
        // if (this.paymentList && this.paymentList.length > 0) {
        //   await this.APMoneyCheck(this.paymentList)
        //   console.log('this.APMoneyCheck(this.paymentList)', this.isPreserve2)
        //   if (!this.isPreserve2) {
        //     return
        //   }
        // }
        
        saveDetail(data).then(res => {
          // eslint-disable-next-line eqeqeq
          if (res.status == '200') {
            if (res.data.projectRequestFundsList) {
              this.list = res.data.projectRequestFundsList
              for (let y = 0; y < this.list.length; y++) {
                this.list[y].listIndex = y;
              }
            }
            if (res.data.projectVendorList) {
              this.vendorList = res.data.projectVendorList;
              for (let y = 0; y < this.vendorList.length; y++) {
                this.vendorList[y].vendorNameOld = this.vendorList[y].vendorName
                this.vendorList[y].listIndex = y;
              }
            }
            if (res.data.projectPaymentList) {
              this.paymentList = res.data.projectPaymentList;
              for (let y = 0; y < this.paymentList.length; y++) {
                this.paymentList[y].listIndex = y;
              }
            }
            if (res.data.projectProgress) {
              this.projectProgress = res.data.projectProgress;
              this.projectProgress.projectNoOld = this.projectProgress.projectNo;
            }
            this.$message.success(this.$t('scheduleManager.worksDetails.saveSuccess')); // 保存成功
            this.$store.getters.pageState[str] = {}
            this.getData().then(() => {
              if (this.likeVendor) {
                // console.log(this.likeVendor, 'this.likeVendor')
                this.queryVendor()
              }
              if (this.likeVendor2) {
                // console.log(this.likeVendor2, 'this.likeVendor2')
                this.queryVendor2()
              }
            })
          } else {
            this.$message.error(res.message);
          }
        });
      },
      total(arry, code, amount) {
        const newfood = [];
        const temp = {};
        for (const i in arry) {
          const key = arry[i][code];
          if (temp[key]) {
            temp[key][code] = temp[key][code];
            temp[key][amount] = temp[key][amount] + arry[i][amount];
          } else {
            temp[key] = {};
            temp[key][code] = arry[i][code];
            temp[key][amount] = arry[i][amount];
          }
        }
        for (const k in temp) {
          newfood.push(temp[k])
        }
        return newfood;
      },
      // 将字符串转换成数字
      changeToNum(nums) {
        let num = nums
        if (num && typeof num === 'string') {
          // 转数字
          num = Number(num)
          if (isNaN(num)) {
            num = 0
          }
        }
        if (!num) {
          num = 0
        }
        if (num && (typeof num !== 'string' || typeof num !== 'number')) {
          num = 0
        }
        return num;
      },
      // 同一单号之下付款金额提交时必须等于查询时金额总和
      // 请款
      async ARMoneyCheck(newArr) {
        const arr = []; // 有金额单号集合
        const receivabArr = []
        newArr.forEach(res => {
          if (res.erpReceivablesNo) {
            // const args = this.changeToNum(res.requestFundsMoney)
            receivabArr.push({
              OMA01: res.erpReceivablesNo,
              ARMONEY: isNaN(Number(res.requestFundsMoney)) ? 0 : Number(res.requestFundsMoney)
            })
            if (arr.length >= 0 && !arr.includes(res.erpReceivablesNo)) {
              arr.push(res.erpReceivablesNo);
            }
          }
        });
        /**
         * 通过单号获取单号api集合  判断同一单号之下求和是否相等
         */
        let queryReceivabArr = [];
        await queryARMoney(arr).then(res => {
          queryReceivabArr = res.data
          if (queryReceivabArr.length > 0) {
            const arrs = this.total(receivabArr, 'OMA01', 'ARMONEY');
            console.log('arrs', JSON.stringify(arrs))
            console.log('queryReceivabArr', JSON.stringify(queryReceivabArr))
            for (let i = 0; i < arrs.length; i++) {
              for (let j = 0; j < queryReceivabArr.length; j++) {
                if (arrs[i].OMA01 === queryReceivabArr[j].OMA01) {
                  if (arrs[i].ARMONEY !== queryReceivabArr[j].ARMONEY) {
                    console.log('comingss')
                    this.$message.error(this.$t('scheduleManager.worksDetails.equalsRequestTip')); // '請款作業每一筆ERP應收單號對應的請款金額之和必須等於ERP應收單號的金額'
                    this.isPreserve = false;
                    break
                  }
                }
              }
              // if (!isPreserve) {
              //   break
              // }
            }
          }
        });
        // return isPreserve
      },
      // 付款
      async APMoneyCheck(newArr) {
        const arr = []; // 有金额单号集合
        const payableArr = []
        newArr.forEach(res => {
          if (res.erpPayableNo) {
            // const args = this.changeToNum(res.expectedPaymentMoney)
            payableArr.push({
              APA01: res.erpPayableNo,
              APMONEY: isNaN(Number(res.expectedPaymentMoney)) ? 0 : Number(res.expectedPaymentMoney)
            })
            if (arr.length >= 0 && !arr.includes(res.erpPayableNo)) {
              arr.push(res.erpPayableNo);
            }
          }
        });
        /**
         * 通过单号获取单号api集合  判断同一单号之下求和是否相等
         */
        let queryPayablebArr = [];
        await queryAPMoney(arr).then(res => {
          queryPayablebArr = res.data
          if (queryPayablebArr.length > 0) {
            const arrs = this.total(payableArr, 'APA01', 'APMONEY');
            console.log('arrs', JSON.stringify(arrs))
            console.log('queryPayablebArr', JSON.stringify(queryPayablebArr))
            // queryReceivabArr 和 arr 有相同APA01单号的金额是否相同,如果有一个不相同 则提示
            for (let i = 0; i < arrs.length; i++) {
              for (let j = 0; j < queryPayablebArr.length; j++) {
                console.log('arrs[i]', arrs[i].APA01)
                console.log('queryPayablebArr[j]', queryPayablebArr[j].APA01)
                if (arrs[i].APA01 === queryPayablebArr[j].APA01) {
                  if (arrs[i].APMONEY !== queryPayablebArr[j].APMONEY) {
                    console.log('coming')
                    this.$message.error(this.$t('scheduleManager.worksDetails.equalsPaymentTip')); // '付款作業的預計付款金額之和必須等於該ERP應付單號對應的金額'
                    this.isPreserve2 = false;
                    break
                  }
                }
              }
              // if (!isPreserve) {
              //   break
              // }
            }
          }
        });
        // return isPreserve
      }
    },
    watch: {
      projectProgress: {
        handler(newValue) {
          console.log('payStatus')
          /* if (this.payStatusFla === 0) {
            this.$set(this.projectProgress, 'payStatus', '0')
          } */
          // if (this.projectType === 0) {
          //   this.$set(this.projectProgress, 'projectType', '0')
          // }
          // isRequestFunds 可否請款 有PO核准日帶出「可請款」；有PO核准日且PO金額為0帶出「不可請款」；其他為「待PO」。
          if (newValue.hasOwnProperty('poApprovalDate')) {
            if (this.projectProgress.poApprovalDate != null) {
              if (newValue.hasOwnProperty('poApprovalMoney')) {
                // eslint-disable-next-line eqeqeq
                if (this.projectProgress.poApprovalMoney != null && this.projectProgress.poApprovalMoney != 0 && this.projectProgress.poApprovalMoney !== '') {
                  this.$set(this.projectProgress, 'isRequestFunds', '2')
                } else {
                  this.$set(this.projectProgress, 'isRequestFunds', '1')
                }
              } else {
                this.$set(this.projectProgress, 'isRequestFunds', '1')
              }
            } else {
              this.$set(this.projectProgress, 'isRequestFunds', '0')
            }
          } else {
            this.$set(this.projectProgress, 'isRequestFunds', '0')
          }

          // 监听 专案工程 实际完工日 有值时 完工%为100%
          if (newValue.systemType === 'E') {
            if (newValue.realityFinishDate) {
              this.$set(this.projectProgress, 'completedPercent', 100)
            }
          }


          const obj = { // 页面储存
            pageRouting: '/progressManager/worksDetails',
            id: this.id ? this.id : 'addWorks',
            projectProgress: this.projectProgress,
            list: this.list, // 3、请款作业
            vendorList: this.vendorList, // 4、厂商管理
            paymentList: this.paymentList, // 5、付款作业
            projectRequestFundsVo: this.projectRequestFundsVo,
            projectVendorVo: this.projectVendorVo,
            projectPaymentVo: this.projectPaymentVo
          }
          store.dispatch('addPageState', obj)
        },
        deep: true
      },
      vendorList: {
        handler(newValue) {
          console.log('newvendorList')
          this.vendorPoMoneySum = 0
          if (!this.vendorList || this.vendorList.length === 0) {
            this.$set(this.projectProgress, 'payStatus', '3')
            // this.projectProgress = Object.assign({}, this.projectProgress, { payStatus: '3' })
            console.log('33333')
            console.log(this.projectProgress)
          } else {
            console.log('other')
            if (!this.paymentList || this.paymentList.length === 0) {
              this.$set(this.projectProgress, 'payStatus', '0')
              // this.projectProgress = Object.assign({}, this.projectProgress, { payStatus: '0' })
              console.log('000000')
              console.log(this.projectProgress)
            } else {
              this.payStatusFla = 0
              for (let i = 0; i < this.paymentList.length; i++) {
                if (this.paymentList[i].realityPaymentDate == null) {
                  this.payStatusFla += 0
                } else {
                  if (this.paymentList[i].hasOwnProperty('realityPaymentDate') && this.paymentList[i].realityPaymentDate !== '') {
                    this.payStatusFla += 1
                  } else {
                    this.payStatusFla += 0
                  }
                }
                // if (!newValue[i].paymentIs) newValue[i].paymentIs = "0"
              }
              // eslint-disable-next-line eqeqeq
              if (this.payStatusFla == this.paymentList.length && this.paymentList.length !== 0) {
                // 如果每条记录都有实际付款日 为 付款完成
                this.$set(this.projectProgress, 'payStatus', '2')
                console.log('22222222')
                // this.projectProgress = Object.assign({}, this.projectProgress, { payStatus: '2' })
              } else {
                if (this.payStatusFla > 0) {
                  // 有部分记录存在实际付款日 为 部份付款
                  this.$set(this.projectProgress, 'payStatus', '1')
                  console.log('111111')
                  // this.projectProgress = Object.assign({}, this.projectProgress, { payStatus: '1' })
                } else if (this.payStatusFla === 0 || this.paymentList.length === 0) {
                  // 没有任何实际付款日 为 待付款
                  this.$set(this.projectProgress, 'payStatus', '0')
                  // this.projectProgress = Object.assign({}, this.projectProgress, { payStatus: '0' })
                  console.log('0000000        ====')
                }
              }
            }
          }
          for (let i = 0; i < newValue.length; i++) {
            if (newValue[i].vendorPoMoney === '' || newValue[i].vendorPoMoney === undefined) {
              this.vendorPoMoneySum += 0
            } else {
              this.vendorPoMoneySum += Number(newValue[i].vendorPoMoney)
            }
          }
          if (this.vendorPoMoneySum !== 0 && this.receivablesMoneySum !== 0) {
            const aa = Math.round(this.vendorPoMoneySum / this.receivablesMoneySum * 100);
            this.$set(this.projectProgress, 'vendorDiscount', aa)
          }
          const obj = { // 页面储存
            pageRouting: '/progressManager/worksDetails',
            id: this.id ? this.id : 'addWorks',
            projectProgress: this.projectProgress,
            list: this.list, // 3、请款作业
            vendorList: this.vendorList, // 4、厂商管理
            paymentList: this.paymentList, // 5、付款作业
            projectRequestFundsVo: this.projectRequestFundsVo,
            projectVendorVo: this.projectVendorVo,
            projectPaymentVo: this.projectPaymentVo
          }
          store.dispatch('addPageState', obj)
        },
        deep: true
      },
      // 请款作业
      list: {
        handler(newValue) {
          this.receivablesMoneySum = 0
          let realityReceivablesDateIndex = 0
          let invoiceDateIndex = 0

          for (let i = 0; i < newValue.length; i++) {
            if (newValue[i].hasOwnProperty('realityReceivablesDate')) {
              if (newValue[i].realityReceivablesDate != null) {
                realityReceivablesDateIndex += 1
              }
            }
            if (newValue[i].hasOwnProperty('invoiceDate')) {
              if (newValue[i].invoiceDate != null) {
                invoiceDateIndex += 1
              }
            }
            if (newValue[i].receivablesMoney === '' || newValue[i].receivablesMoney === undefined) {
              this.receivablesMoneySum += 0
            } else {
              this.receivablesMoneySum += Number(newValue[i].receivablesMoney)
            }
          }
          if (this.list.length > 0 && realityReceivablesDateIndex === this.list.length) {
            this.tableName = 'cancelOrderDate'
          } else {
            this.tableName = ''
            if (this.list.length > 0 && invoiceDateIndex === this.list.length) {
              this.tableName = 'endCaseDate'
            } else {
              this.tableName = ''
            }
          }
          if (this.vendorPoMoneySum !== 0 && this.receivablesMoneySum !== 0) {
            const aa = Math.round(this.vendorPoMoneySum / this.receivablesMoneySum * 100);
            this.$set(this.projectProgress, 'vendorDiscount', aa)
          }
          const obj = { // 页面储存
            pageRouting: '/progressManager/worksDetails',
            id: this.id ? this.id : 'addWorks',
            projectProgress: this.projectProgress,
            list: this.list, // 3、请款作业
            vendorList: this.vendorList, // 4、厂商管理
            paymentList: this.paymentList, // 5、付款作业
            projectRequestFundsVo: this.projectRequestFundsVo,
            projectVendorVo: this.projectVendorVo,
            projectPaymentVo: this.projectPaymentVo
          }
          store.dispatch('addPageState', obj)
        },
        deep: true
      },
      paymentList: {
        handler(newValue) {
          this.payStatusFla = 0
          for (let i = 0; i < newValue.length; i++) {
            if (newValue[i].realityPaymentDate == null) {
              this.payStatusFla += 0
            } else {
              if (newValue[i].hasOwnProperty('realityPaymentDate') && newValue[i].realityPaymentDate !== '') {
                this.payStatusFla += 1
              } else {
                this.payStatusFla += 0
              }
            }
            // if (!newValue[i].paymentIs) newValue[i].paymentIs = "0"
          }
          // eslint-disable-next-line eqeqeq
          if (this.payStatusFla == newValue.length && newValue.length !== 0) {
            // 如果每条记录都有实际付款日 为 付款完成
            this.$set(this.projectProgress, 'payStatus', '2')
          } else {
            if (this.payStatusFla > 0) {
              // 有部分记录存在实际付款日 为 部份付款
              this.$set(this.projectProgress, 'payStatus', '1')
            // eslint-disable-next-line eqeqeq
            } else if (this.payStatusFla === 0 || newValue.length === 0) {
              // 没有任何实际付款日 为 待付款
              this.$set(this.projectProgress, 'payStatus', '0')
            }
          }

          if (!this.vendorList || this.vendorList.length === 0) {
            this.$set(this.projectProgress, 'payStatus', '3')
          }

          const obj = { // 页面储存
            pageRouting: '/progressManager/worksDetails',
            id: this.id ? this.id : 'addWorks',
            projectProgress: this.projectProgress,
            list: this.list, // 3、请款作业
            vendorList: this.vendorList, // 4、厂商管理
            paymentList: this.paymentList, // 5、付款作业
            projectRequestFundsVo: this.projectRequestFundsVo,
            projectVendorVo: this.projectVendorVo,
            projectPaymentVo: this.projectPaymentVo
          }
          store.dispatch('addPageState', obj)
        },
        deep: true
      },
    }
  };
</script>
<style lang="scss" scoped>
  .app-wrapper .save_buttom {
    width: -webkit-fill-available;
    background-color: white;
    position: fixed;
    bottom: 0;
    //margin: 0 20px;
    margin-left: 20px;
    margin-right: 230px;
    height: 50px;
    z-index: 2000;
  }
  .hideSidebar .save_buttom {
    width: -webkit-fill-available;
    background-color: white;
    position: fixed;
    bottom: 0;
    //margin: 0 20px;
    margin-left: 20px;
    margin-right: 55px;
    height: 50px;
    z-index: 2000;
  }
  .box{
    padding: 0 15px !important;
    height: 36px;
    line-height: 36px;
    text-align: center;
    border-radius: 4px;
    color: #333;
    cursor:text;
    font-size: 12px;
  }
  .box:empty:before{
    content: attr(placeholder);
    color: #c0c4cc;
    font-size: 12px;
  }
  .display_center{
    display: flex;
    justify-content: center;
    align-items: center;
  }
  /deep/ .el-checkbox__original{
    opacity: 0;
    outline: none;
    position: absolute;
    margin: 0;
    width: 0;
    height: 0;
    left: 0px !important;
    z-index: -1;
  }
  .el-input.is-disabled /deep/ .el-input__inner {
    color: #333;
    cursor: not-allowed;
  }
</style>
